Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-23-2008, 07:59 PM
Junior Member
 
Join Date: Mar 2008
Posts: 12
Default Zend_Form: howto render

Hi,
sorry to ask such a simple newbie question, I just started to work with ZF.

Simplest form:
Code:
<?php
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
$form = new Zend_Form();
$form->addElement('text', 'username');
$form->addElement('password', 'password');
$form->addElement('submit', 'login');
?>
No custom decorators, and nothing fancy ;-)
How do I output this form (I am not using any MVC)?
I know, that Zend_View is used by Zend_Form:
(Akra’s DevNotes Blog Archive Simple Zend_Form Example
I have red comment 39 by Matthew.
Obviously I got the error: ViewHelper decorator cannot render without a registered view object.
So, how Do I register a view object?

I googled around, searched the docs (15.2.3. Render a form), but:
echo $form;
or
echo $form->render();
errors out, view object for render is optional?

The docs say:
Quote:
By default, Zend_Form and Zend_Form_Element will attempt to use the view object initialized in the ViewRenderer, which means you won't need to set the view manually when using the Zend Framework MVC.
From this it follows that I have to set the view manually, if not using MVC.
How is this done?
Thanks,
Friedhelm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-24-2008, 05:47 PM
Junior Member
 
Join Date: Mar 2008
Posts: 12
Thumbs up Solved

Answering myself, bit too late yesterday ;-)
Quote:
Originally Posted by friedhelm View Post
Hi,
sorry to ask such a simple newbie question, I just started to work with ZF.

Simplest form:
Code:
<?php
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
$form = new Zend_Form();
$form->addElement('text', 'username');
$form->addElement('password', 'password');
$form->addElement('submit', 'login');
?>
Simply added
Code:
$form->setView(new Zend_View());
echo $form;
Thanks,
Friedhelm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-28-2008, 11:38 AM
ubk ubk is offline
Junior Member
 
Join Date: Mar 2008
Posts: 1
Default

Quote:
Originally Posted by friedhelm View Post
Answering myself, bit too late yesterday ;-)


Simply added
Code:
$form->setView(new Zend_View());
echo $form;
Thanks,
Friedhelm
You saved my life
Thank you!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-28-2008, 12:22 PM
Junior Member
 
Join Date: Mar 2008
Posts: 12
Default Glad to hear

Quote:
Originally Posted by ubk View Post
You saved my life
Thank you!!!
I think, this should be mentionend in the docs, maybe I should submit an issue.

/friedhelm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:21 AM.