我到处搜索但找不到答案,所以问题是,装饰类必须在哪里,让我们看一个例子:
我有 application/forms/Guestbook.php
class Application_Form_Guestbook extends Zend_Form
{
public function init()
{
$this->addPrefixPath('My_Decorator', '/application/forms/decorator', 'decorator');
$this->setMethod('post');
$this->addElement('text', 'email', array(
'label' => 'Your email address',
'require' => true,
'filters' => array('StringTrim'),
'validators' => array('EmailAddress'),
//'prefixPath' => array('decorator' => array('My_Decorator' => 'application/forms/decorator')),
'decorators' => array(array('SimpleInput'))));
// Add the comment element
$this->addElement('textarea', 'comment', array(
'label' => 'Please Comment:',
'required' => true,
'validators' => array(
array('validator' => 'StringLength', 'options' => array(0, 20))
)
));
// Add a captcha
$this->addElement('captcha', 'captcha', array(
'label' => 'Please enter the 5 letters displayed below:',
'required' => true,
'captcha' => array(
'captcha' => 'Figlet',
'wordLen' => 5,
'timeout' => 300
)
));
$this->addElement('submit', 'submit', array('ignore' => true, 'label' => 'Sign Guestbook'));
$this->addElement('hash', 'csrf', array('ignore' => true));
}
}
并有 application/forms/decorator/SimpleInput.php
class My_Decorator_SimpleInput extends Zend_Form_Decorator_Abstract
{
protected $_format = '<label for="%s">%s !!!!!!</label><input id="%s" name="%s" type="text" value="%s"/>';
public function render($content)
{
$element = $content->getElement();
$name = htmlentities($element->getFullyQualifiedName());
$label = htmlentities($element->getLabel());
$id = htmlentities($element->getId());
$value = htmlentities($element->getValue());
$markup = sprintf($this->_format, $name, $label, $id, $name, $value);
return $markup;
}
}
当我尝试启动页面时,我在加载装饰器时出错:
An error occurred
Application error
Exception information:
Message: Plugin by name 'SimpleInput' was not found in the registry; used paths: My_Decorator_: /application/forms/decorator/ Zend_Form_Decorator_: Zend/Form/Decorator/
Stack trace:
#0 /home/dev/public_html/local.zend.test/library/Zend/Form/Element.php(1827): Zend_Loader_PluginLoader->load('SimpleInput')
#1 /home/dev/public_html/local.zend.test/library/Zend/Form/Element.php(2207): Zend_Form_Element->_getDecorator('SimpleInput', NULL)
#2 /home/dev/public_html/local.zend.test/library/Zend/Form/Element.php(1980): Zend_Form_Element->_loadDecorator(Array, 'SimpleInput')
#3 /home/dev/public_html/local.zend.test/library/Zend/Form/Element.php(316): Zend_Form_Element->getDecorators()
#4 /home/dev/public_html/local.zend.test/library/Zend/Form/Element.php(271): Zend_Form_Element->loadDefaultDecorators()
#5 /home/dev/public_html/local.zend.test/library/Zend/Form.php(1125): Zend_Form_Element->__construct('email', Array)
#6 /home/dev/public_html/local.zend.test/library/Zend/Form.php(1035): Zend_Form->createElement('text', 'email', Array)
#7 /home/dev/public_html/local.zend.test/application/forms/Guestbook.php(18): Zend_Form->addElement('text', 'email', Array)
#8 /home/dev/public_html/local.zend.test/library/Zend/Form.php(240): Application_Form_Guestbook->init()
#9 /home/dev/public_html/local.zend.test/application/controllers/GuestbookController.php(28): Zend_Form->__construct()
#10 /home/dev/public_html/local.zend.test/library/Zend/Controller/Action.php(516): GuestbookController->signAction()
#11 /home/dev/public_html/local.zend.test/library/Zend/Controller/Dispatcher/Standard.php(308): Zend_Controller_Action->dispatch('signAction')
#12 /home/dev/public_html/local.zend.test/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#13 /home/dev/public_html/local.zend.test/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#14 /home/dev/public_html/local.zend.test/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#15 /home/dev/public_html/local.zend.test/public/index.php(26): Zend_Application->run()
#16 {main}
此示例来自快速指南。问题是这些装饰器的位置必须在哪里(默认位置),或者我如何加载它们以及我应该写哪个“路径/到/装饰器”(从根\应用程序\表单文件夹?),因为 Zend 中的文档通常很难看。 .. =\