Php 班级';SYMBONY\Component\Form\Form&\x27;表单提交期间在链配置的命名空间中找不到
我正在构建一个界面,允许办公室里的人编辑特定记录的详细信息。目前我有这样一个表格: view.html.twigPhp 班级';SYMBONY\Component\Form\Form&\x27;表单提交期间在链配置的命名空间中找不到,php,forms,symfony,Php,Forms,Symfony,我正在构建一个界面,允许办公室里的人编辑特定记录的详细信息。目前我有这样一个表格: view.html.twig <!-- Modal Windows: Edit Instructor Personal Details --> <div id="editPersonal" style="display:none;"> <div class="modal-head"> <h2>Edit Personal Details For
<!-- 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>
编辑以下人员的个人详细信息:{{讲师.firstName}{{{讲师.姓氏}}
{{form_标签(ipde.id,'id*',{'attr':{'class':'title'}}}}}
{{form_errors(ipde.id)}
{{form_小部件(ipde.id,{'attr':{'class':'textfield'}}}}
{{form_标签(ipde.firstName,'firstName*',{'attr':{'class':'title'}}}}}
{{form_errors(ipde.firstName)}
{{form_小部件(ipde.firstName,{'attr':{'class':'text'}}}}
{{form_标签(ipde.names,'names*',{'attr':{'class':'title'}}}}}
{{形式错误(ipde.姓氏)}
{{form_widget(ipde.names,{'attr':{'class':'text'}}}}
{form_标签(ipde.address1,'地址行1*',{'attr':{'class':'title'}}}}}
{{form_errors(ipde.address1)}
{{form_小部件(ipde.address1,{'attr':{'class':'text'}}}}}
{form_标签(ipde.address2,'地址行2',{'attr':{'class':'title'}}}}}
{{form_errors(ipde.address2)}
{{form_小部件(ipde.address2,{'attr':{'class':'text'}}}}
{{form_标签(ipde.town,'town*',{'attr':{'class':'title'}}}}}
{{form_errors(ipde.town)}
{{form_小部件(ipde.town,{'attr':{'class':'text'}}}}
{{form_标签(ipde.county,'county*',{'attr':{'class':'title'}}}}}
{{表格错误(ipde.county)}
{{form_小部件(ipde.county,{'attr':{'class':'text'}}}}
{{form_标签(ipde.postcode,'postcode*',{'attr':{'class':'title'}}}}}
{{form_errors(ipde.postcode)}
{{form_小部件(ipde.postcode,{'attr':{'class':'text'}}}}
{{form_标签(ipde.email,'email*',{'attr':{'class':'title'}}}}}
{{form_errors(ipde.email)}
{{form_小部件(ipde.email,{'attr':{'class':'text'}}}}
{{form_rest(ipde)}
我的控制器如下所示:
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()
));
}
}
在所有*Type()类中都有“use”语句吗?
我想应该是这样的
use Symfony\Component\Form\AbstractType;
AbstractType使用表单名称空间。在所有*Type()类中都有“use”语句吗?
我想应该是这样的
use Symfony\Component\Form\AbstractType;
AbstractType使用表单名称空间。您正在持久化$ipde
,它恰好是一个表单而不是一个实体
这可能是错误的根源。您正在持久化$ipde
,它恰好是一个表单而不是一个实体
这可能是错误的根源。我已经检查过了,并且在*Type类中包含了该名称空间。但是没有快乐!我已经检查过了,并且在*Type类中包含了该名称空间。但是没有快乐!那么,我该如何将表单持久化到数据库中呢?我想这就是我首先要做的…应该在数据库中持久化的是实体,而不是表单,在您的情况下,应该是$instructorQ
,我猜,那么,我该如何将表单持久化到数据库中呢?我想这就是我首先要做的…应该在数据库中持久化的实体,而不是表单,在您的情况下,我想应该是$instructorQ