English 中文(简体)
根据一名控制者/行动内部的请求,大力制作表格
原标题:Zend creating forms based on requests within one controller/action

I don t really know how to word the title well, but here s my issue. I decided instead of having 25 controllers to handle pages, I have one PageController with a viewAction that takes in a :page parameter - for example, http://localhost/website/page/about-us would direct to PageController::viewAction() with a parameter of page = about-us. All of the pages are stored in a templates folder, so the viewrenderer is set to render application emplatesdefaultabout-us.phtml.

我这样做是能够巩固的,似乎是一种更好的办法。 我的问题是:如果要求页数为contact-us,我需要一个Zend_Form,以便在联系页内使用。 因此,我需要在<代码>PageController:viewAction()中找到一种形式,建立形式,并在提交材料的基础上处理需要(或许应该以抽象的过程方法处理,而不是确定)。

我不知道如何执行。 我认为,我可以储存一栏,其名称为表格和连接页识别码。 更糟的是,建立一个单向一页的表格,然后,如果提交,则通过表格和核对表填写,然后处理(可能的话,在表格中采用<代码>>。 我确实不知道如何处理这一问题,并且正在寻求能够得到的任何帮助。

感谢!

问题回答

这里可以想到的是,这可能有助于你的工作,或有助于你的工作方向。

只有当你需要一页以上表格时,你必须做超出这种自动处理形式以外的事情时,这才算好。

为页数所附表格(如申请/格式/页)设定标准位置。 这里将保留与网页有关的自动表格。

在您的<代码>viewAction中,您可利用自动载荷查看该页是否有表格。 例如:

$page  = $this->getParam( page );
$page  = ucfirst(preg_replace( /-(w)/ie , "strtoupper( $1 )", $page)); // contact-us -> ContactUs
$class =  Application_Form_Page_  . $page;

// class_exists will invoke the autoloader to map a class to a file
if (class_exists($class)) {
    // a form is defined for this page
    $form = new $class();

    // check if form was posted
    if ($this->getRequest()->isPost()) {
        if ($form->isValid($this->getRequest()->getPost()) {
            // form is valid - determine how to process it
        }
    }

    // assign the form to the view
    $this->view->pageForm = $form;
}

All this really leaves out is the action you take to process a specific form. Since the contact form will likely generate an email, and another form may insert data into a database, you will need some sort of callback system or perhaps another class that can be mapped automatically which contains the form processor code.

沿着这些思路说出的一点是首先想到的,我希望这有助于给你更多的想法。





相关问题
Zend 邮件问题,涉及外国char子+ com子

泽斯德邮局在名称被定为具有外国性质(如“保”)和 com(”)的物品时,就放弃了一种例外(因为邮局(邮局)退回假)。 重新提出以下守则。

PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

Link to a specific step in onepage checkout

Is it possible to redirect the browser to nth step in the onepage checkout? If so, how would one go about doing it? I m working on a payment module and have a sort of "cancel" action that i would ...

Tagging with Zend Framework

I m trying to create the same solutions as below, but using a simple MySQL query (instead of the static version used below where the words/tags are implemented in the code). The name of the MySQL ...

dynamicaly adding textboxes to zend_form

I hope that this is a quick question to answer. I am developing a form using Zend_Form, I have a number of Zend_Dojo_Form_Element_Textboxs to add to this form dynamically. These are added from rows ...

热门标签