独立的 Zend 表单
当我使用以下代码创建表单时,我可以使用 Zend 表单作为独立组件:
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();
$form = new Zend_Form;
... create and add zend form elements here
//display form
echo $form->render(new Zend_View());
但是,我无法弄清楚如何添加自定义表单元素和验证。我创建了自定义元素和验证表单电话号码和社会安全号码。但我无法将它们添加到独立的表单中。
有人可以提供建议吗?我提前感谢大家。
I can use Zend form as a stand alone component when I am creating forms using the following code:
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();
$form = new Zend_Form;
... create and add zend form elements here
//display form
echo $form->render(new Zend_View());
However, I cannot I figure out how I can add custom form elements and validation. I created custom element and validation form phone number and social security number. But I cannot add them to a stand alone form.
Could someone kindly advice? I thank you all in advance.
您必须向自动加载器注册所需的名称空间。
默认情况下,自动加载器将仅加载 Zend 组件。
在您的情况下,您似乎需要执行以下操作
$autoloader->registerNamespace( '我的' );
确保库文件夹位于您的包含路径中。
然后您应该能够使用/自动加载您的“我的”组件。
You'll have to register the namespace that you want with the autoloader.
The autoloader will, by default, only load Zend components.
It looks like in your case you'll want to do the following
$autoloader->registerNamespace( 'My' );
Make sure the library folder is in your include path.
You should then be able to use/autoload your My components.