Magento默认控制器动作 [英] Magento default controller action

查看:84
本文介绍了Magento默认控制器动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为每个动作创建一个函数? 例如我有功能:

How to create a function for every action? for example I have function:

 public function indexAction()
    {

        $this->loadLayout();     
        $this->renderLayout();
    }

但这是针对动作索引的,但是当我不知道动作或其动态创建时,该怎么办呢,例如,动作可以是controller/someaction,controller/someaction2 我想创建将处理此问题的默认功能

but this is for action index, but what when I don't know action, or its created dynamiclly, so for example action could be controller/someaction, controller/someaction2 I would like to create default function which will handle this

推荐答案

我个人会这样做:
1-我将创建一个继承自Zend_Controller_Action的抽象类,如下所示:

I personally would do something like this:
1 - I would create an abstract class inheriting from Zend_Controller_Action like this:

<?php
abstract Class Yourlibrary_Controller_ControllerAbstract extends Zend_Controller_Action
{

    public function preDispatch()
    {
        $this->loadLayout();     
        $this->renderLayout();
    }

2-我的控制器继承了 Yourlibrary_Controller_ControllerAbstract ,而不是 Zend_Controller_Action

我在preDispatch()中做过,但您也可以在postDispatch中做
您还可以添加变量,并且控制器使用这些变量执行或不执行代码

2 - My Controllers inherit Yourlibrary_Controller_ControllerAbstract not Zend_Controller_Action

I did in the preDispatch() but you can also do it in the postDispatch
You can also add variables and controllers use these variables execute the code or not

这篇关于Magento默认控制器动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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