Hello,

I am having the same problem as first outlined in this thread.

The solution Matthew posted does not work. Can anyone help?

Thanks,

David



Matthew Weier O'Phinney-3 wrote:
> 
> -- Paul Cook <[email protected]> wrote
> (on Wednesday, 21 May 2008, 02:00 PM -0400):
>> I'm trying to use components of the Framework in a project that currently
>> is
>> not MVC.  Eventually I'd like to refactor to MVC but that is not possible
>> right
>> now.
>> 
>> I'm using Zend_Form and ran into an error that I can't figure out.  I'm
>> trying
>> to use the ViewScript decorator and I've read through the Decorators with
>> Zend
>> Form arcticle and scoured the web but now I'm stuck.
>> 
>> The error I get is: Warning: ViewHelper decorator cannot render without a
>> registered view object
>> 
>> Some code: formt_test.php (in tests folder and main script)
>> 
>> require_once('Zend/View.php');
>> require_once('TestForm.php');
>> 
>> $form = new TestForm();
>> 
>> echo $form->render(new
>> Zend_View(array('basePath'=>'/path/to/tests/views')));
> 
> Hmm. I see what the issue is here. Override the setView() method of your
> form object with the following:
> 
>     public function setView(Zend_View_Interface $view) 
>     {
>         parent::setView($view);
>         foreach ($this as $item) {
>             $item->setView($view);
>         }
>         return $this;
>     }
> 
> That _should_ correct the issue for you.
> 
> The problem you're running into is that the form object has the view
> object, but it's not injecting into its elements, display groups, etc.
> The above should take care of that.
> 
> 
>> TestForm.php
>> 
>> require_once 'Zend/Form.php';
>> require_once 'Zend/Form/Element/Select.php';
>> 
>> class TestForm extends Zend_Form
>> {
>>         public function init()
>>         {
>>             $this->setAction("/test_action");
>>             $this->setMethod("post");
>>            
>>             $statuses = array(
>>                 'Booked'=>'Booked',
>>                 'Cancelled'=>'Cancelled',
>>                 'Pending'=>'Pending',
>>                 );
>> 
>>             $types = array(
>>                 'Public'=>'Public',
>>                 'Private'=>'Private'
>>             );
>>            
>>             $this->addElement(new Zend_Form_Element_Select('status'));
>>             $this->addElement(new
>> Zend_Form_Element_Select('event_type'));
>>            
>>             $this->getElement('status')->addMultiOptions($statuses);
>>             $this->getElement('event_type')->addMultiOptions($types);
>>            
>>             $this->setDecorators(array(
>>                 array('ViewScript',
>> array('viewScript'=>'test_form.phtml'))
>>             ));
>>            
>>         }
>> }
>> 
>> test_form.phtml
>> 
>> <form action="<?= $this->escape($this->element->getAction()) ?>"
>> method="<?=
>> $this->escape($this->element->getMethod()) ?>">
>> 
>>             <fieldset>
>>             <legend>Test Form</legend>
>>                     <table id='edit_test' style='width: 650px;'>
>>                     <tr>
>>                         <td class='edit_mem'>Event Status:<br /><?=
>> $this->
>> element->status ?></td>
>>                         <td class='edit_mem'>Event Type:<br /><?= $this->
>> element->event_type ?></td>
>>                     </tr>
>>                     </table>
>>                     </fieldset>
>>                 </fieldset>
>> </form>
>> 
>> 
>> Any help would be greatly appreciated.  Thanks in advance.
> 
> -- 
> Matthew Weier O'Phinney
> Software Architect       | [email protected]
> Zend - The PHP Company   | http://www.zend.com/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Zend_Form-without-MVC-problem-tp17375245p22987792.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to