我有两个控制器,它们有一些非常相同的动作.如何在另一个控制器中引用相同的动作?
class UserController extends Zend_Controller_Action {
public function listAction() {
//do something here
}
}
class AdminController extends Zend_Controller_Action {
public function listAction() {
//how to call UserController::listAction here?
}
}
Run Code Online (Sandbox Code Playgroud)
我在上面的AdminController :: listAction中放了什么,以便我只需要在UserController :: listAction中编写代码?
谢谢
小智 7
我会使用一个控制器动作帮助器,如果你再次做同样的事情就可以重用它.
class My_Controller_Action_Helper_Whatever
{
public function direct()
{
return $this;
}
public function doSomething($paramA, $paramB)
{
// code
return $whatever;
}
}
Run Code Online (Sandbox Code Playgroud)
然后在您的控制器中实现:
class UserController extends Zend_Controller_Action
{
public function someAction()
{
$this->getHelper('Whatever')->doSomething($a, $b);
}
}
class AdminController extends Zend_Controller_Action
{
public function anotherAction()
{
$this->getHelper('Whatever')->doSomething($a, $b);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
414 次 |
| 最近记录: |