2011-06-22 4 views
5

तो, मैं फ़ॉर्म के लिए कक्षा बनाने के बिना किसी अन्य रूप में एक फॉर्म एम्बेड करने की कोशिश कर रहा हूं। Heres क्या Ive हालांकिसिम्फनी 2 सबफॉर्म

$form = $this 
     ->buildForm('UserAlert', $alert) 
     ->add('Alert', 'entity', array('class' => 'Blah\MgmtBundle\Entity\Alert', 'property' => 'name', 'required' => true)) 
     ->add('Site', 'entity', array('class' => 'Blah\MgmtBundle\Entity\Site', 'property' => 'name', 'required' => false)) 
     ->add('Keyword', 'entity', array('class' => 'Blah\MgmtBundle\Entity\Keyword', 'property' => 'name', 'required' => false)) 
     ->add('Variant', 'entity', array('class' => 'Blah\MgmtBundle\Entity\Variant', 'property' => 'name', 'required' => false)) 
     ->add('Name', 'text'); 


    $uac = $alert->getUserAlertConfig(); 
    $subform = $this 
     ->buildForm('UserAlertConfig', $uac) 
     ->add('EmailAlert', 'choice', array('choices' => array('1' => 'Yes', '0' => 'No'), 'required' => true, 'label' => 'Email Alerts')) 
     ->add('EmailHours', 'text', array('required' => false, 'label' => 'Email Alert Hours')) 
     ->add('TextAlert', 'choice', array('choices' => array('1' => 'Yes', '0' => 'No'), 'required' => true, 'label' => 'Text Alerts')) 
     ->add('TextHours', 'text', array('required' => false, 'label' => 'Text Alert Hours')); 

    $form->add($subform); 
    $form = $form->getForm(); 

मिला, getForm() समारोह पर, अपने कह

Neither property "form" nor method "getForm()" nor method "isForm()" exists in class "Blah\MgmtBundle\Entity\UserAlert" 

किसी को भी किसी भी विचार कैसे im इस quickloading सामान का उपयोग कर काम करने के लिए प्राप्त करने के लिए माना जाता है?

यहाँ buildForm

public function buildForm($model = '', $data) 
{ 
    if (empty($model)) { 
     throw new \Exception("Must define a model"); 
    } 
    return $this->get('form.factory')->createBuilder('form', $data, array('data_class' => "\\Blah\\MgmtBundle\\Entity\\$model")); 
} 


    Stack Trace 
in /mnt/www/reporting/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php at line 314  
at PropertyPath ->readProperty (object(UserAlert), '0') 
in /mnt/www/reporting/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php at line 191  
at PropertyPath ->getValue (object(UserAlert)) 
in /mnt/www/reporting/vendor/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php at line 64 
at PropertyPathMapper ->mapDataToForm (object(UserAlert), object(Form)) 
in /mnt/www/reporting/vendor/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php at line 55 
at PropertyPathMapper ->mapDataToForms (object(UserAlert), array('_token' => object(Form), 'Alert' => object(Form), 'Site' => object(Form), 'Keyword' => object(Form), 'Variant' => object(Form), 'Name' => object(Form), 'form' => object(Form))) 
in /mnt/www/reporting/vendor/symfony/src/Symfony/Component/Form/Form.php at line 404  
at Form ->setData (object(UserAlert)) 
in /mnt/www/reporting/vendor/symfony/src/Symfony/Component/Form/FormBuilder.php at line 659  
at FormBuilder ->getForm() 
in /mnt/www/reporting/src/Blah/MgmtBundle/Controller/AlertController.php at line 96  
at AlertController ->editAction ('1') 
in at line  
at call_user_func_array (array(object(AlertController), 'editAction'), array('1')) 
in kernel.root_dir/bootstrap.php.cache at line 438  
at HttpKernel ->handleRaw (object(Request), '1') 
in kernel.root_dir/bootstrap.php.cache at line 416  
at HttpKernel ->handle (object(Request), '1', true) 
in /mnt/www/reporting/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php at line 44  
at HttpKernel ->handle (object(Request), '1', true) 
in kernel.root_dir/bootstrap.php.cache at line 612  
at Kernel ->handle (object(Request)) 
in /mnt/www/reporting/web/app_dev.php at line 12  
+0

इस नियंत्रक कोड है है? या कस्टम फॉर्म प्रकार कोड? –

+0

इसे नियंत्रक में, क्षमा करें – Ascherer

+0

और 'buildForm' विधि को परिभाषित किया गया है कहां? क्या आप अपना सोर्स कोड पोस्ट कर सकते हैं? –

उत्तर

4

उप-प्रपत्र के लिए एक इंटरफेस बनाने और इंटरफेस बनाने के बिना इस

$form = $this 
     ->buildForm('UserAlert', $alert) 
     ->add('Alert', 'entity', array('class' => 'Neokeo\MgmtBundle\Entity\Alert', 'property' => 'name', 'required' => true)) 
     ->add('Site', 'entity', array('class' => 'Neokeo\MgmtBundle\Entity\Site', 'property' => 'name', 'required' => false)) 
     ->add('Keyword', 'entity', array('class' => 'Neokeo\MgmtBundle\Entity\Keyword', 'property' => 'name', 'required' => false)) 
     ->add('Variant', 'entity', array('class' => 'Neokeo\MgmtBundle\Entity\Variant', 'property' => 'name', 'required' => false)) 
     ->add('Name', 'text'); 

    $uac = $alert->getUserAlertConfig(); 



    $subform = $this->buildForm('UserAlertConfig', $uac, new \Neokeo\MgmtBundle\Form\UserAlertConfig) 
     ->add('EmailAlert', 'choice', array('choices' => array('0' => 'No', '1' => 'Yes'), 'required' => true, 'label' => 'Email Alerts')) 
     ->add('TextAlert', 'choice', array('choices' => array('0' => 'No', '1' => 'Yes'), 'required' => true, 'label' => 'Text Alerts')); 

    $form->add($subform, '', array('label' => '')); 
    $form = $form->getForm(); 

की तरह इसे जोड़ने किसी को भी एक आसान तरीका मिल सकता है समाप्त, मुझे पता है

+0

मैं कहूंगा कि आप की जरूरत नहीं होनी चाहिए' getForm() 'के रूप में' के साथ एक समस्या हो रही im $ फॉर्म' पहले से ही आपका फॉर्म है। 'फॉर्मफॉर्मर' के साथ 'getForm() 'का उपयोग किया जाता है, है ना? –

+0

'बिल्डफॉर्म'' फॉर्मबिल्डर 'वापस कर रहा है – Ascherer

0

प्रयास करें

$form->add('The name of the UserAlertConfig property in the UserAlert entity', $subform); 

आप संपत्ति नाम निर्दिष्ट किए बिना ऐड पद्धति के लिए एक FormBuilder वस्तु पार कर लेते हैं, यह FormBuilder ऑब्जेक्ट का नाम (जो 'form' है) का उपयोग करता है संपत्ति के नाम के रूप में। UserAlert इकाई में form नाम की कोई संपत्ति नहीं है।

+0

ठीक कर सकता हूं, यह काम नहीं कर रहा था, लेकिन जब मैं इसे फ्लिप करता हूं, '$ form-> जोड़ें ($ subform,' userAlertConfig ');' यह मुझे थोड़ा करीब ले जाता है। अब प्रॉक्सी lol 'प्रकार का तर्क यह अपेक्षित" \ Neokeo \ MgmtBundle \ इकाई \ UserAlert "," प्रॉक्सी \ NeokeoMgmtBundleEntityUserAlertConfigProxy "given' – Ascherer