全站点Zend_Form [英] Site wide Zend_Form

查看:54
本文介绍了全站点Zend_Form的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何向我的layout.phtml中添加表单?

How can I add a form to my layout.phtml?

我希望能够拥有一个搜索表单和一个登录表单,该表单可以保留在我网站上的每个表单中.

I would like to be able to have a search form and a login form that persists through every form on my site.

推荐答案

我有一篇博客文章对此进行了解释:

I have a blog post explaining this: http://blog.zero7ict.com/2009/11/how-to-create-reusable-form-zend-framework-zend_form-validation-filters/

在应用程序"文件夹中创建一个表单"文件夹

In your Application folder create a Forms folder

这是示例表格:

<?php
class Form_CreateEmail extends Zend_Form
{
public function __construct($options = null)
{
    parent::__construct($options);

    $this->setName('createemail');
    $title = new Zend_Form_Element_Text('title');
    $title->setLabel('Subject')
    ->setRequired(true)
    ->addFilter('StripTags')
    ->addFilter('StringTrim')
    ->addValidator('NotEmpty');
    $info = new Zend_Form_Element_Textarea('info');
    $info->setLabel('Email Content')
    ->setAttribs(array('rows' => 12, 'cols' => 79)); 
    $submit = new Zend_Form_Element_Submit('submit');
    $submit->setAttrib('id', 'submitbutton');
    $this->addElements(array($title, $info, $submit));
}

}
?>

然后您可以像这样从控制器调用它:

You can then call it from your controller like this:

$form = new Form_CreateEmail();
        $form->submit->setLabel('Add');
        $this->view->form = $form;

并使用

echo $this->form;

希望这会有所帮助.

如果希望将此内容包含在每个页面中,则可以创建一个新的帮助文件

if you want this to be included on everypage you could create a new helper file

在您的views文件夹中创建一个helpers文件夹并创建一个loginHelper.php文件

in your views folder create a helpers folder and create a loginHelper.php file

class Zend_View_Helper_LoginHelper
{
    function loginHelper()
    {

$form = new Form_CreateEmail();
        $form->submit->setLabel('Add');
        return = $form;

    }
}

这可以使用以下方法从您的布局中输出:

This could be output from your layout using:

<?php echo $this->LoginHelper(); ?>     

这篇关于全站点Zend_Form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆