Zend ViewScript Decorator the big picture, overall use.how to?

DJDif007

New Member
It's true I've seen a lot of examples on stackoverflow and many from Google search but apparently nobody showed the big picture of how things falls under one another, even from the manual itself. I've just picked Zend Framework(1.10.8) and when creating forms I've finally found that the ViewScript for now is much easier for me to configure but wasn't the case. I have a\[code\]module booking\[/code\], with \[code\]UserController\[/code\] and \[code\]createAction\[/code\] in it.Under \[code\]/application/modules/booking/views/scripts/user\[/code\] I have \[code\]create.phtml\[/code\] and \[code\]custormerForm.phtml\[/code\].From my understanding, at the end of everything my form with it's rendering will be shown in my \[code\]create.phtml\[/code\] as in my form will use the \[code\]customerForm.phtml\[/code\] for it's visual and injected in the create view.So I went ahead and created a simple form\[code\]function init(){ $this->setMethod("post"); $name = New Zend_Form_Element_Text("name"); $name->setLabel("Name: ") ->setOptions(array("size"=>"35")) ->setRequired(true) ->addValidator("NotEmpty", true); $surname = New Zend_Form_Element_Text("surname"); $surname->setLabel("Surname: ") ->setOptions(array("size"=>"35")) ->setRequired(true) ->addValidator("Alpha", true); $this->addElement($name) ->addElement($surname) ->addElement($submit);}\[/code\]Now here is the createAction in UserController\[code\]public function createAction(){ $this->view->show = "Please Enter your Details"; $form = new Hotel_Form_Entity(); $form->setAction("/booking/user/create"); //and here set the for to be displayed at described in customerForm view $form->setDecorators(array(array('ViewScript',array('viewScript'=>'customerForm.phtml')))); //so here i set the form to form variable accessible in create view $this->view->form = $form; if($this->getRequest()->isPost()){ if($form->isValid($this->getRequest()->getPost())){ $values = $form->getValues(); $this->_helper->flashMessenger("Thank you.Form processed"); $this->_forward("success","user","booking",$values); } }}\[/code\]Now these are the create.phtml and customerForm.phtml\[code\]<!-- create.phtml --><h4><?php echo $this->show; ?></h4><br/><!-- --><p><?php echo $this->form; ?></p><br/> <!-- customerForm.phtml --> <div style="padding: 10 0 0 15; border: solid 1.5px #999"> <form action="<?php echo $this->element->getAction(); ?>" method="<?php echo $this->element->getMethod(); ?>"> <table> <tr> <td><?php echo $this->element->name; ?></td> <td></td> </tr> <tr> <td></td> <td><?php echo $this->element->surname; ?></td> </tr> <tr> <td colspan="2"><?php echo $this->element->submit; ?> </td> </tr> </table> </form> </div>\[/code\]so when I hit my page as in http://localhost/project/booking/user/createit just displays the layout with the content of the create view with no form. Nothing in page source, no errors.Did I get the wrong idea on how to use this or I'm just doing something wrong in the code?And since i'm using Zend framework 1.10.8 there seems not to be any tutorial covering the whole thing on ViewScript decorator. Can anyone please give me a hand and share his valuable experience here? Thank you very much for reading this. Maybe I'll make this a tutorial who knows :D
 
Top