Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony 2编辑操作未填充表单字段_Php_Mysql_Symfony_Doctrine_Twig - Fatal编程技术网

Php Symfony 2编辑操作未填充表单字段

Php Symfony 2编辑操作未填充表单字段,php,mysql,symfony,doctrine,twig,Php,Mysql,Symfony,Doctrine,Twig,我正在尝试为用户地址实体创建编辑操作,但无论何时加载页面,它似乎都不会加载相关数据。下面是我的控制器和视图的代码 配置文件控制器: public function addressEditAction($id) { $user = $this->getUser(); if (!is_object($user) || $user instanceof UserInterface) { throw new AccessDeniedExcep

我正在尝试为用户地址实体创建编辑操作,但无论何时加载页面,它似乎都不会加载相关数据。下面是我的控制器和视图的代码

配置文件控制器:

public function addressEditAction($id) {
        $user = $this->getUser();
        if (!is_object($user) || $user instanceof UserInterface) {
            throw new AccessDeniedException('This user does not have access to this section.');
        }

        if ($this->container->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) {
            $em = $this->getDoctrine()->getEntityManager();
            $address = $em->getRepository('SCWDesignsBundle:UserAddresses')->getAddressById($user->getId(), $id);
            if (!$address) {
                throw new NotFoundHttpException(sprintf('Could not find address id: "%s"', $id));
            }

            $form = $this->createForm(new UserAddressesFormType(), $address);

            $request = $this->getRequest();
            if ($request->getMethod() == 'POST') {
                $form->bind($request);
                if ($form->isValid()) {
                    $utilites = new Utilities;
                    $address->setPhone($utilites->stripPhoneNumbers($address->getPhone()));
                    $em->persist($address);
                    $em->flush();

                    return $this->redirect($this->generateUrl('fos_user_profile_show'));
                }
            }
        }

        return $this->render('SCWDesignsBundle:Profile\Address:new.html.twig', array(
            'active_page' => 'profile',
            'form' => $form->createView()
        ));  
    }
视图:

正如您所看到的,我已经从数据库中获得了正确的数据,我已经按照有关将数据绑定到表单对象的说明进行了操作,它只是不能持久保存到视图中。我尝试过多种方法,但似乎都无法奏效。如有任何建议/帮助,将不胜感激

谢谢


Shawn

当表单可能需要单个对象时,您将从存储库中获得一个二维$address数组。

感谢您的响应,今晚我将查看返回值!我不敢相信这是真正的问题。。。非常感谢你。
{% trans_default_domain 'SCWDesignsBundle' %}

{% block modal_block %}
<div class="item-box">
    <h2>Address Details</h2>

    {% include 'SCWDesignsBundle:Default:form_errors.html.twig' %}

    <form action="{{ path('scw_designs_address_add') }}" {{ form_enctype(form) }} method="POST" class="scw_designs_address_new clearfix">
        <div class="address-new">
            <div class="form-item">
                <div class="form-label">
                    <label for="first-name">{{ 'profile.first_name'|trans }}: <span class="required">*</span></label>
                </div>
                <div class="form-field">
                    {{ form_widget(form.first_name) }}
                </div>          
            </div>

            <div class="form-item">
                <div class="form-label">
                    <label for="last-name">{{ 'profile.last_name'|trans }}: <span class="required">*</span></label>
                </div>
                <div class="form-field">
                    {{ form_widget(form.last_name) }}
                </div>
            </div>

            <div class="form-item">
                <div class="form-label">
                    <label for="address">{{ 'profile.address'|trans }}: <span class="required">*</span></label>
                </div>
                <div class="form-field">
                    {{ form_widget(form.address_one) }}
                    {{ form_widget(form.address_two) }}
                </div>              
            </div>

            <div class="form-item">
                <div class="form-label">
                    <label for="city">{{ 'profile.city'|trans }}: <span class="required">*</span></label>
                </div>
                <div class="form-field">
                    {{ form_widget(form.city) }}
                </div>
            </div>

            <div class="form-item">
                <div class="form-label">
                    <label for="country">{{ 'profile.country'|trans }}: <span class="required">*</span></label>
                </div>
                <div class="form-field">
                    {{ form_widget(form.country) }}
                </div>
            </div>

            <div class="form-item">
                <div class="form-label">
                    <label for="state">{{ 'profile.state'|trans }}: <span class="required">*</span></label>
                </div>
                <div class="form-field">
                    {{ form_widget(form.state) }}
                </div>
            </div>

            <div class="form-item">
                <div class="form-label">
                    <label for="zipcode">{{ 'profile.zipcode'|trans }}: <span class="required">*</span></label>
                </div>
                <div class="form-field">
                    {{ form_widget(form.zipcode, { 'attr': { 'class': 'zipcodeUS' }}) }}
                </div>
            </div>

            <div class="form-item">
                <div class="form-label">
                    <label for="phone">{{ 'profile.phone'|trans }}: <span class="required">*</span></label>
                </div>
                <div class="form-field">
                    {{ form_widget(form.phone, { 'attr': { 'class': 'phoneUS' }}) }}
                </div>
            </div>
        </div>

        <div class="modal-button-wrapper">
            {{ form_widget(form._token) }}
            <button type="submit" class="btn-submit primary-button">Save Changes</button>
        </div>
    </form>
</div>
{% endblock %}
array (size=1)
  0 => 
  array (size=11)
    'id' => string '4' (length=1)
    'firstName' => string 'Bruce' (length=5)
    'lastName' => string 'Wayne' (length=5)
    'addressOne' => string '123 Gotham Lane' (length=15)
    'addressTwo' => null
    'city' => string 'Gotham' (length=6)
    'country' => string 'USA' (length=3)
    'zipcode' => string '51478' (length=5)
    'phone' => string '3344796239' (length=10)
    'code' => string 'NH' (length=2)
    'state' => string 'New Hampshire' (length=13)