3

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

1
  • 1
    Ok, problem solved, I didn't overwrite setView method, although I thought I did Commented Oct 26, 2011 at 9:48

3 Answers 3

4

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;
Sign up to request clarification or add additional context in comments.

2 Comments

This is only possible if the controller component of ZF is to be used. This component is part of the MVC implementation of ZF which the OP is not using.
@Hikaru-Shindo: D'oh! That is a very good point; I missed that part of the OP question. ;-) I will note that when I have used Zend_Form without the full ZF MVC stack, it was still possible to make the static call above. Internally, it creates a ViewRenderer instance and assigns the view. Made everything much easier and allowed the form to fall back to using the view stashed cozily away in the ViewRenderer. But, as in most things, YMMV. ;-)
3

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

Comments

3

Zend_Form depends on Zend_View. You also need to use the Zend_View class to make it work.

You may read something on this topic here.

A possible example how to achieve it:

$view = new Zend_View();
$form = new My_Form();

echo $form->render($view);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.