|
I have read through the forums and tried for several hours now to get a simple viewscript to work - I am still unable to get a form element to render. Hopefully someone can offer some advice:
My Controller: <?php class Orders_OrderdetailController extends Zend_Controller_Action{ public function preDispatch(){ $this->_helper->layout->disableLayout(); } public function indexAction(){ ... $form = new OrderDetailForm(); $form->populate($orderData[0]); $this->view->form = $form; ... } } class OrderDetailForm extends Zend_Form{ public function init(){ $this->addElement('text', 'ORDER_NUMBER', array( 'label' => 'Order Number' )); //$ORDER_NUMBER = new Zend_Form_Element_Text('ORDER_NUMBER'); //$ORDER_NUMBER->setLabel('Order Number'); //$this->addElement($ORDER_NUMBER); $this->setDecorators(array(array('viewScript', array('viewScript' => 'orderdetail/orderdetailform.phtml')))); } } _____________________________________________________________________________ My index.phtml view script: Test View Order<?php echo $this->form; ?>_____________________________________________________________________________ My orderdetailform.phtml view script: <?php foreach ($this->element as $item) { $item->setView($this); echo "Setting View<br>"; } ?> <form> Order Detail Form<?php echo $this->ORDER_NUMBER; ?></form> __________________________________________________________________ Can a skilled eye see what's wrong - I have tried so many variations of this and have yet to see a text input element render... Thanks in advance! |
|
Don't have time to go through this in detail, but try to replace:
$this->setDecorators(array(array('viewScript', array('viewScript' => 'orderdetail/orderdetailform.phtml')))) with $this->setDecorators(array(array('ViewScript', array('viewScript' => 'orderdetail/orderdetailform.phtml')))) Note that the first occurance of ViewScript has a capitl V. Do you get any errors when you try to run your code? |
|
Tried your suggestion - this seems to give the same result. No errors - the
Order Detail Formfound in the orderdetailform.phtml is rendered on the page - just no form elements...
|
|
In reply to this post by Goran Juric
I didn't notice your view script is for the Form itself and not for the form element.
In your view script try calling: <?php echo $this->getElement('ORDER_NUMBER')->render();?> render() takes an optional object that implement Zend_View_Interface as a parameter. |
|
Administrator
|
In reply to this post by Erik Olof Wahlstrom
-- edub <[hidden email]> wrote
(on Tuesday, 14 October 2008, 12:24 PM -0700): > I have read through the forums and tried for several hours now to get a > simple viewscript to work - I am still unable to get a form element to > render. Hopefully someone can offer some advice: <snip> > My orderdetailform.phtml view script: > <?php > foreach ($this->element as $item) { > $item->setView($this); > echo "Setting View<br>"; > } > ?> > <form> > <h2>Order Detail Form</h2> > <?php echo $this->ORDER_NUMBER; ?> Change the above to "$this->element->ORDER_NUMBER". The form is in the view script as the "element" property, and you want to grab the element ORDER_NUMBER off the form object. (You're already doing that in the foreach loop at the top of the view script ;-)) > </form> -- Matthew Weier O'Phinney Software Architect | [hidden email] Zend Framework | http://framework.zend.com/ |
|
Thanks Matthew - your suggestion works. One of my sources was the article you wrote at http://devzone.zend.com/article/3450-Decorators-with-Zend_Form and I was trying to implement the ViewScript as you had it in that article:
Like so: Please register with us!<form action="<?= $this->escape($this->form->getAction() ?>"method="<?= $this->escape($this->form->getMethod() ?>"> <fieldset> <legend>Demographics</legend> <p> Please provide us the following information so we can know more about you. </p> <?= $this->form->age ?> <?= $this->form->nationality ?> <?= $this->form->income ?> </fieldset> but within the specified viewscript doesn't $this->form become merely $this? Since in the controller I am passing $this->view->form = $form - I was assuming that what you had above ($this->form->age) would turn in to $this->age... I guess I'm a little confused on the scope of some of these things...
|
| Powered by Nabble | Edit this page |
