我正在尝试使用Zend Framework,遵循quickstart项目并尝试启动我自己的新模块。 我试图实现视图助手,我不断收到以下消息: 消息:方法formDate不存在
堆栈跟踪的最后一个条目:
我有以下文件结构:
quickstart_zend + application + configs + controllers [...] + views + helpers + scripts [...] + library + Application + Form + Element Date.php + View + Helper FormDate.php + public
我在我的public / Bootstrap.php中添加了这个方法:
protected function _initActionHelpers() { Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH.'/../library/Application/View/Helper', 'Application_View_Helper'); Zend_Controller_Action_HelperBroker::addPrefix('Application_View_Helper'); }
我还在我的application.ini中添加了
autoloaderNamespaces[] = "Application" resources.view.helperPath.Application_View_Helper = APPLICATION_PATH "/../library/Application/View/Helper/"
我已经看过一个版本,并且已经尝试过使用resources.view.helperPath.Application_View_Helper_,似乎没有什么能让它发挥作用。
当然,我有一个Users.php表单,我在其中创建一个'date'元素:
// Add a dateOfBirth element $element = new Application_Form_Element_Date('dateOfBirth'); $this->addElement($element);
当然,我有一个Users.php表单,我在其中创建一个'date'元素:
// Add a dateOfBirth element $element = new Application_Form_Element_Date('dateOfBirth'); $this->addElement($element);
在我的视图脚本中,出现错误:
<? echo $form->dateOfBirth->formDate() ?>
我缺少什么让它上班? :-(我到目前为止花了一天时间寻找解决方案
答案 0 :(得分:1)
您收到此错误,因为Zend_Form_Element中没有此类方法。我认为您正在尝试使用视图助手以某种方式显示此表单元素,但如果是这种情况,则最好使用表单装饰器。您可以使用标准装饰器,也可以创建自定义装饰器。查看文档以获取更多信息 - http://framework.zend.com/manual/en/zend.form.decorators.html
答案 1 :(得分:0)
在您使用的数据上正确使用视图助手,如:
在您的视图中(.phtml)
//a view helper should act on a piece of data and return something
//so I assume your formDate() helper takes a date value and reformats it.
<?php echo $this->formDate($this->form->dateOfBirth) ?>
假设您使用标准将表单分配给控制器中的视图:
$this->view->form = $form;