+ -
当前位置:首页 → 问答吧 → 求助zend_form的问题

求助zend_form的问题

时间:2009-06-03

来源:互联网



<?php
class IndexController extends Zend_Controller_Action
{
function init()
{
$this->registry = Zend_Registry::getInstance();
$this->view = $this->registry['view'];
$this->view->baseUrl = $this->_request->getBaseUrl();
}
function indexAction()
{
$content = \"welcome to php world.\";
$this->view->bodyTitle = '<font color=\"#ff0000\">'.$content.\"</font>\";
echo $this->view->render('index.phtml');
}
function goAction(){
Zend_Loader::loadClass('test_class_myNews');
$news = new test_class_myNews();
$news->showInfo();
echo \"ok\";
}
function __call($func,$argments)
{
echo \"对不起,您访问的数据不存在。\";
echo \"function :\" . $func . \",argments:\" . $argments . \" 不存在\";
}

function showAction(){

$form = new Zend_Form();
$form->setMethod('post')
->setAction('/index/show');
$username = new Zend_Form_Element_Text('username');
$username->setRequired(true);

$form->addElement($username);
$this->view->form = $form;
echo $this->view->render('/index/show.phtml');

}
}
?>


访问http://www.***.com/index.php/index/show 报错如下:

Warning: Exception caught by form: ViewHelper decorator cannot render without a registered view object Stack Trace: #0 D:\Php_Web\DedeAMPZ\WebRoot\Zend_Learn\library\Zend\Form\Element.php(1911): Zend_Form_Decorator_ViewHelper->render('') #1 D:\Php_Web\DedeAMPZ\WebRoot\Zend_Learn\library\Zend\Form\Decorator\FormElements.php(101): Zend_Form_Element->render() #2 D:\Php_Web\DedeAMPZ\WebRoot\Zend_Learn\library\Zend\Form.php(2595): Zend_Form_Decorator_FormElements->render('') #3 D:\Php_Web\DedeAMPZ\WebRoot\Zend_Learn\library\Zend\Form.php(2610): Zend_Form->render() #4 D:\Php_Web\DedeAMPZ\WebRoot\Zend_Learn\app\default\views\scripts\index\show.phtml(2): Zend_Form->__toString() #5 D:\Php_Web\DedeAMPZ\WebRoot\Zend_Learn\library\Zend\View.php(107): include('D:\Php_Web\Dede...') #6 D:\Php_Web\DedeAMPZ\WebRoot\Zend_Learn\library\Zend\View\Abstract.php(832): Zend_View->_run('.\app\default\v...') #7 D:\Php_Web\DedeAMPZ\WebRoot\Zend_Learn\app\default\controllers\IndexController.php(41): Zend_View_Abstract->render('/index/show.pht... in D:\Php_Web\DedeAMPZ\WebRoot\Zend_Learn\library\Zend\Form.php on line 2615

我把index.php中的
$front->setParam('noViewRender',true)修改为false,就可以正常显示zend_form构造的内容,不知道是为什么,请高手指点!!!谢谢!!!

[ 本帖最后由 蓝水宝盒 于 2009-6-3 23:35 编辑 ]

作者: ewayfly   发布时间: 2009-06-03

“ViewHelper decorator cannot render without a registered view”这提示是说你的VIEW的还没有注册,所以不能render,出错。

所以,当你“$front->setParam('noViewRender',true)修改为false”也就是关闭了render,那么也就不会出错了。

作者: 蓝水宝盒   发布时间: 2009-06-03

楼主你看看楼上的解答哦

作者: chinaz   发布时间: 2009-06-04

不错,顶一下..















=700) window.open('http://www.discuz.net/images/default/sigline.gif');" onload="if(this.offsetWidth>'700')this.width='700';if(this.offsetHeight>'700')this.height='700';" >
斗破苍穹 http://www.shucheng.com/book/5/5575/

作者: 霞奕严   发布时间: 2009-09-30