【发布时间】:2011-05-02 19:20:38
【问题描述】:
我目前正在学习 Zend Framework,遇到了以下语法。
class Zend_Controller_Action_Helper_Redirector extends Zend_Controller_Action_Helper_Abstract
{
/**
* Perform a redirect to an action/controller/module with params
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return void
*/
public function gotoSimple($action, $controller = null, $module = null, array $params = array())
{
$this->setGotoSimple($action, $controller, $module, $params);
if ($this->getExit()) {
$this->redirectAndExit();
}
}
/**
* direct(): Perform helper when called as
* $this->_helper->redirector($action, $controller, $module, $params)
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return void
*/
public function direct($action, $controller = null, $module = null, array $params = array())
{
$this->gotoSimple($action, $controller, $module, $params);
}
}
在 Zend Framework 中,可以使用以下语法调用此类中的 direct() 方法:
$this->_helper->redirector('index','index');
重定向器是 _helper 对象中的一个对象(!),它位于控制器对象内部,我们在其中调用方法。这里的语法糖是你可以将参数传递给对象而不是方法,我们可以这样写:
$this->_helper->redirector->gotoSimple('index','index');
..当然,这一切都很好。
这是我的问题:这个 direct() 方法在 OO PHP 中是标准的吗?或者这个功能是内置在 Zend 框架中的吗? 我找不到这方面的任何文档。
谢谢!
【问题讨论】:
标签: php oop zend-framework syntactic-sugar