在链配置的名称空间中找不到类

在链配置的名称空间中找不到类

本文介绍了在表单提交期间,在链配置的名称空间中找不到类“Symfony \ Component \Form\Form”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个界面,允许办公室的人员编辑特定记录的详细信息。目前我有这样一个表格:

view.html.twig

 <! -  Modal Windows:编辑教师个人详细信息 - > 
< div id =editPersonalstyle =display:none;>
< div class =modal-head>
< h2>编辑个人详细信息:< font-color =red!important> {{instructor.firstName}} {{instructor.surname}}< / font>< / h2>
< / div>
< div class =modal-body>
< form action =#method =post{{form_enctype(ipde)}} id =editPersonalDetailsclass =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 =modal:closeclass =closebutton>无保存关闭< / a>
< input type =submitvalue =Save Changesid =savebuttonprclass =savebutton/>
{{form_rest(ipde)}}
< / div>
< / div>
< / div>

我的Controller看起来像这样:

DefaultController.php

 <?php 

命名空间PCUK \\ \\InstructorBundle\Controller;

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

class DefaultController extends Controller
{

public function viewAction($ instructor,Request $ request)
{
//数据库连接
$ insrep = $ this-> getDoctrine() - > getManager();

//获取教师从实体获取表单使用
$ instructorQ = $ insrep-> getRepository('InstructorBundle:MapInstructors') - > find($ instructor);
$ b $ //获取表单的实体共享分支使用
$ instructorS = $ insrep-> getRepository('InstructorBundle:MapInstructorShared') - > find($ instructor);

//生成表单以编辑教师个人详细信息
$ ipde = $ this-> createForm(new IpdeType(),$ instructorQ);

//处理表单提交以编辑教师个人详细信息
if($ request-> getMethod()=='POST'){
$ ipde-> bind $要求提供);

if($ ipde-> isValid()){
//执行一些操作,例如将任务保存到数据库

// if( $ this-> request-> isXmlHttpRequest()){
//返回ajax需要的数据。
//}
$ em = $ this-> getDoctrine() - > getManager();
$ em-> persist($ ipde);
$ em-> flush();


return $ this->重定向($ this-> generateUrl('task_success'));



//生成表单以编辑教师记录
$ ir = $ this-> createForm(new IrType(),$ instructorQ);

//生成表单以编辑教师记录
$ ba = $ this-> createForm(new BaType(),$ instructorS);
$ b $ //返回数据以查看
返回$ this-> render('InstructorBundle:Default:view.html.twig',array(
'ipde'=> $ ipde-> createView(),
'ir'=> $ ir-> createView(),
'ba'=> $ ba-> createView()
));
}
}

但是,当我去提交表单时,以下错误:

我已经构建了一个Symfony2项目,并且已经引用它来反对这个当前项目,看看是否包含 Symfony \ Component \Form\Form ,如果这实际上是问题所在。



发生了什么?

解决方案

c> $ ipde 这恰好是一个不是实体的表单!



这可能是错误的根源。


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

<!-- 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

<?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:

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.

What's happening?

解决方案

you are persisting $ipde which happens to be a form not an entity !

that's probably the source of error.

这篇关于在表单提交期间,在链配置的名称空间中找不到类“Symfony \ Component \Form\Form”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 18:30