2013-04-23 27 views
1

我正在構建一個界面,允許辦公室的人員編輯特定記錄的詳細信息。目前,我有這樣的形式:在表單提交期間在鏈配置的名稱空間中找不到類「Symfony Component Form Form」

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> 

我的控制器看起來像這樣:

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() 
     )); 
    } 
} 

然而,當我去提交表單時,出現以下錯誤:

"The class 'Symfony\Component\Form\Form' was not found in the chain configured namespaces PCUK\InstructorBundle\Entity"

我已經建立之前Symfony2的項目,我引用這對這個當前的項目,看看是否我已經包括了Symfony\Component\Form\Form,如果這是真正的問題是什麼。

發生了什麼事?

回答

10

你是堅持$ipde這恰好是一種形式不是實體!

這可能是錯誤的根源。

+0

那麼,如何將表單持久化到數據庫呢?我認爲這就是我在做的第一個地方...... – mickburkejnr 2013-04-24 10:31:19

+0

它是應該堅持在數據庫中的實體,而不是形式,在你的情況下,這將是'$ instructorQ'我猜 – zizoujab 2013-04-24 15:53:05

0

在所有* Type()類中是否有「use」語句? 我想應該是這樣

use Symfony\Component\Form\AbstractType; 

AbstractType有使用形式的命名空間。

+0

我已經檢查過,並且在* Type類中包含了該名稱空間。雖然沒有歡樂! – mickburkejnr 2013-04-24 08:39:43

+0

可能@zizoujab是對的,錯過了。 – farghost 2013-04-24 09:12:02

相關問題