creating forms in zend with ini file
I know Zend_Form gets a lot of hate from many developers, I've even heard that for many it was the main turn-off to switching from [insert random php framework name here] to ZF, but just a little time ago I found out that creating forms with an .ini file is the way around this and the best way of doing it. I haven't found any useful info googling around it, can anyone po开发者_运维百科int me the right path to it?
Thanks a lot.
Create the ini file eg. (we will use forms.ini for this example)
[production]
user.login.elements.LastName.type = "text"
user.login.elements.LastName.options.label = "Last Name:"
(save it to ../configs/forms.ini)
In the bootstrap you need to intialize it, something like this:
$forms = new Zend_Config_Ini(APPLICATION_PATH . '/configs/forms.ini', 'production');
Zend_Registry::set('forms', $forms);
then in your controller you call it
$forms = Zend_Registry::get('forms');
$form = new Zend_Form($forms->user->login);
$this->view->form = $form;
and on your view you would display it by using either
<?php echo $this->form ;?>
or if you were trying to access just one form element from the login set you would do something like this
<?php echo $this->form->LastName ;?>
hope this is what you were looking for
Check this out. It's stated in the official manual at this page: http://framework.zend.com/manual/1.12/en/zend.form.quickstart.html
Scroll down to the section called "Using a Zend_Config Object". There you got some examples.
As mentioned in the doc, the Zend_Config factory will ingest the .ini file describing your form. After that, you can build a Zend_Form using that Zend_Config instance.
$config = new Zend_Config_Ini($configFile, 'development');
$form = new Zend_Form($config->user->login);
精彩评论