Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend-form without Zend-Framework MVC - viewscript isn't displaying elements, but they exists and are displayed by var_dump()

When I try to do something like

 <?=$this->element->mailCiteCheck?>

nothing is displaying.

However, when I do:

<?=var_dump($this->element->mailCiteCheck);?>

I get:

object(Zend_Form_Element_Checkbox)#118 (33) {
  ["checked"]=>
  bool(false)
  ["helper"]=>
  string(12) "formCheckbox"
  ["options"]=>
  array(2) {
    ["checkedValue"]=>
    string(1) "1"
    ["uncheckedValue"]=>

And so on... so how can I display elements of this form?

And when I do

<?=$this->element->mailCiteCheck;die();?>

I get this warning:

ViewHelper decorator cannot render without a registered view object

like image 751
rukya Avatar asked Dec 06 '25 10:12

rukya


2 Answers

As noted in the link provided by @Hikaru:

By default, Zend_Form and Zend_Form_Element will attempt to use the view object initialized in the ViewRenderer

So instead of overriding the form's render() method or manually calling $form->setView($view), an alternate approach is to just set the view into the ViewRenderer, possibly during Bootstrap:

Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view = $view;
like image 106
David Weinraub Avatar answered Dec 07 '25 23:12

David Weinraub


The answer was to set view to all form elements:

    $view = new Zend_View();
    $view->addScriptPath(APPLICATION_FORM_SCRIPT_PATH);
    $view->addBasePath(APPLICATION_SCRIPT_PATH);
    $replyForm = new Form_MailReply();
    $replyForm->setView($view);
    foreach ($replyForm as $item){
        $item->setView($view);
    }
    $replyForm->render($view);
like image 21
rukya Avatar answered Dec 08 '25 00:12

rukya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!