【发布时间】:2012-07-31 20:00:52
【问题描述】:
我正在尝试使用自定义表单元素制作独立的 Zend 表单。我需要使用自定义视图助手来创建这个元素。如何在没有 application.ini 文件的情况下注册自定义视图帮助程序路径?
set_include_path(
implode(PATH_SEPARATOR, array(
get_include_path(),
PATH_TO_ZF_LIBRARY
)));
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace( 'My' );
$form = new Zend_Form;
... create and add zend form elements here
//display form
echo $form->render(new Zend_View());
另外,自定义 Zend_Form_Element 是否知道在新路径中寻找自定义助手?根据文档,我所要做的就是使用视图助手的类名创建 public $helper var。但我不知道这是否适用于自定义视图助手。
class My_Form_Element_Ssn extends Zend_Form_Element_Xhtml
{
public $helper = 'ssnElement';
public function setValue()
{
}
public function getValue()
{
return '12345';
}
}
class My_View_Helper_SsnElement
extends Zend_View_Helper_FormElement
{
public function ssnElement( $name, $value = null, $attribs = null )
{
return 'SSN';
}
}
提前感谢您的帮助。
【问题讨论】: