简体   繁体   English

在提交表单期间,在链配置的名称空间中找不到类'Symfony \\ Component \\ Form \\ Form'

[英]The class 'Symfony\Component\Form\Form' was not found in the chain configured namespaces during Form Submission

I'm building an interface that will allow people in the office to edit details of specific records. 我正在建立一个界面,使办公室中的人员可以编辑特定记录的详细信息。 Currently I have a form like this: 目前,我有这样的表格:

view.html.twig view.html.twig

<!-- Modal Windows: Edit Instructor Personal Details -->
<div id="editPersonal" style="display:none;">
    <div class="modal-head">
        <h2>Edit Personal Details For: <font-color="red !important">{{instructor.firstName}} {{instructor.surname}}</font></h2>
    </div>
    <div class="modal-body">
        <form action="#" method="post" {{ form_enctype(ipde) }} id="editPersonalDetails" class="modaledit">
        <table class="modalform-col1">
            <tbody>
                <tr class="hidden">
                    <th>{{ form_label(ipde.id, 'ID*', { 'attr': {'class': 'title'} }) }}</th>
                    <td>
                        {{ form_errors(ipde.id) }}
                        {{ form_widget(ipde.id, { 'attr': {'class': 'textfield'}}) }}
                    </td>
                </tr>
                <tr>
                    <th>{{ form_label(ipde.firstName, 'First Name*', { 'attr': {'class': 'title'} }) }}</th>
                    <td>
                        {{ form_errors(ipde.firstName) }}
                        {{ form_widget(ipde.firstName, { 'attr': {'class': 'text'}}) }}
                    </td>
                </tr>
                <tr>
                    <th>{{ form_label(ipde.surname, 'Surname*', { 'attr': {'class': 'title'} }) }}</th>
                    <td>
                        {{ form_errors(ipde.surname) }}
                        {{ form_widget(ipde.surname, { 'attr': {'class': 'text'}}) }}
                    </td>
                </tr>
                <tr>
                    <th>{{ form_label(ipde.address1, 'Address Line 1*', { 'attr': {'class': 'title'} }) }}</th>
                    <td>
                        {{ form_errors(ipde.address1) }}
                        {{ form_widget(ipde.address1, { 'attr': {'class': 'text'}}) }}
                    </td>
                </tr>
                <tr>
                    <th>{{ form_label(ipde.address2, 'Address Line 2', { 'attr': {'class': 'title'} }) }}</th>
                    <td>
                        {{ form_errors(ipde.address2) }}
                        {{ form_widget(ipde.address2, { 'attr': {'class': 'text'}}) }}
                    </td>
                </tr>
                <tr>
                    <th>{{ form_label(ipde.town, 'Town*', { 'attr': {'class': 'title'} }) }}</th>
                    <td>
                        {{ form_errors(ipde.town) }}
                        {{ form_widget(ipde.town, { 'attr': {'class': 'text'}}) }}
                    </td>
                </tr>
                <tr>
                    <th>{{ form_label(ipde.county, 'County*', { 'attr': {'class': 'title'} }) }}</th>
                    <td>
                        {{ form_errors(ipde.county) }}
                        {{ form_widget(ipde.county, { 'attr': {'class': 'text'}}) }}
                    </td>
                </tr>
                <tr>
                    <th>{{ form_label(ipde.postcode, 'Postcode*', { 'attr': {'class': 'title'} }) }}</th>
                    <td>
                        {{ form_errors(ipde.postcode) }}
                        {{ form_widget(ipde.postcode, { 'attr': {'class': 'text'}}) }}
                    </td>
                </tr>
                <tr>
                    <th>{{ form_label(ipde.email, 'Email*', { 'attr': {'class': 'title'} }) }}</th>
                    <td>
                        {{ form_errors(ipde.email) }}
                        {{ form_widget(ipde.email, { 'attr': {'class': 'text'}}) }}
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="modal-footer">
        <div class="modal-placeright">
            <a href="#close" rel="modal:close" class="closebutton">Close Without Saving</a>
            <input type="submit" value="Save Changes" id="savebuttonpr" class="savebutton" />
            {{ form_rest(ipde) }} 
        </div>
    </div>
</div>

And my Controller looks like this: 我的控制器看起来像这样:

DefaultController.php DefaultController.php

<?php

namespace PCUK\InstructorBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use PCUK\InstructorBundle\Form\IpdeType;
use PCUK\InstructorBundle\Form\IrType;
use PCUK\InstructorBundle\Form\BaType;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{

    public function viewAction($instructor, Request $request)
    {
        // Database connection
        $insrep = $this->getDoctrine()->getManager();

        // Get Instructor from Entity for Form use
        $instructorQ = $insrep->getRepository('InstructorBundle:MapInstructors')->find($instructor);

        // Get Shared Branches from Entity for Form use
        $instructorS = $insrep->getRepository('InstructorBundle:MapInstructorShared')->find($instructor);

        // Generate Form to edit Instructor Personal Details
        $ipde = $this->createForm( new IpdeType(), $instructorQ);

        // Handle Form submission to edit Instructor Personal Details
        if ($request->getMethod() == 'POST') {
            $ipde->bind($request);

            if ($ipde->isValid()) {
                // perform some action, such as saving the task to the database

                //if ($this->request->isXmlHttpRequest()){
                       //return data ajax requires.
                //}
                $em = $this->getDoctrine()->getManager();
                $em->persist($ipde);
                $em->flush();


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

        // Generate Form to edit Instructor Records
        $ir = $this->createForm( new IrType(), $instructorQ);

        // Generate Form to edit Instructor Records
        $ba = $this->createForm( new BaType(), $instructorS);

        // Return data to view
        return $this->render('InstructorBundle:Default:view.html.twig', array(
            'ipde' => $ipde->createView(),
            'ir' => $ir->createView(),
            'ba' => $ba->createView()
        ));
    }
}

However, when I go to submit the form I get the following error: 但是,当我提交表单时,出现以下错误:

"The class 'Symfony\\Component\\Form\\Form' was not found in the chain configured namespaces PCUK\\InstructorBundle\\Entity" “在链配置的名称空间PCUK \\ InstructorBundle \\ Entity中找不到类'Symfony \\ Component \\ Form \\ Form'”

I have built a Symfony2 project before and I've referenced it against this current project to see if I've included the Symfony\\Component\\Form\\Form , if that's actually what the problem is. 我之前已经构建了一个Symfony2项目,并且已针对当前项目引用了该项目,以查看是否包含了Symfony\\Component\\Form\\Form ,如果这确实是问题所在。

What's happening? 发生了什么?

you are persisting $ipde which happens to be a form not an entity ! 您正在坚持的$ipde恰好是形式而不是实体!

that's probably the source of error. 那可能是错误的根源。

Do you have a "use" statement in all of your *Type() classes? 您所有的* Type()类中都有“ use”语句吗? i guess it should be like 我想应该是

use Symfony\Component\Form\AbstractType;

AbstractType have a use of Form namespace. AbstractType具有使用Form命名空间的功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在链配置的名称空间App \\ Entity中找不到类&#39;App \\ Form \\ Database_InteractionType&#39; - The class 'App\Form\Database_InteractionType' was not found in the chain configured namespaces App\Entity Symfony 4-找不到类Symfony \\ Component \\ Form \\ AbstractType - Symfony 4 - Class Symfony\Component\Form\AbstractType not found Symfony + Doctrine ODM“在链配置的名称空间CoreBundle / Document中找不到该类” - Symfony + Doctrine ODM “The class was not found in the chain configured namespaces CoreBundle/Document” Symfony2 - 在链配置的命名空间中找不到类“X” - Symfony2 - The class 'X' was not found in the chain configured namespaces Symfony 错误在链配置的命名空间 XXX 中找不到类 XXX - Symfony error The class XXX was not found in the chain configured namespaces XXX MappingException - 在链配置的命名空间 xxx 中找不到 class 'generalBundle\Entity\xxx' - 升级到 symfony flex - MappingException - The class 'generalBundle\Entity\xxx' was not found in the chain configured namespaces xxx - Upgrade to symfony flex FatalErrorException:错误:未找到类&#39;Symfony \\ Component \\ Form \\ Exception \\ FormException&#39; - FatalErrorException: Error: Class 'Symfony\Component\Form\Exception\FormException' not found 在链配置的名称空间异常中找不到Symfony2多个文件上载 - Symfony2 Multiple File Upload was not found in the chain configured namespaces exception 在链配置的命名空间中找不到类“App\\Entity\\Users” - The class 'App\Entity\Users' was not found in the chain configured namespaces 在链配置的名称空间中找不到类&#39;DoctrineModule \\ Stdlib \\ Hydrator \\ DoctrineObject&#39; - The class 'DoctrineModule\Stdlib\Hydrator\DoctrineObject' was not found in the chain configured namespaces
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM