Domanda

I have tried adding a partial to my form using the Zend Form's viewScript decorator, however i seem unable to pass along variables to the partial. Here's my code:

In the controller i add the form:

$form = new Content_Form_ContentForm(array("categories" => $sortedCategories));
$form->submit_button->setLabel("Add content");
$this->view->form = $form;

Then inside the form i add the viewscript:

public function setCategories($categories) {
    $this->setDecorators(array(array('ViewScript', array(
            'viewScript' => 'partials/dtreePartial.phtml',
            'List'=>"{$categories}",
    ))));
}

I have tried printing the options for the view script by using print_r($this->getDecorator('ViewScript')->getOptions()); wich results in Array ( [viewScript] => partials/dtreePartial.phtml [List] => Array ) However when i run it all, the script returns an error about the List not existing.

I have the feeling i am missing something but i am unsure as to what it is. Any advice or solutions will be appreciated! :)

È stato utile?

Soluzione

The problem is with this line:

'List'=>"{$categories}",

Because you put the variable inside quotes, it gets cast to a string. In PHP, when you cast an array to a string, the result is always the word Array.

Simply change to:

'List'=> $categories,

and it should work as you expect.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top