CakeFest 2024: The Official CakePHP Conference

Yaf_Controller_Abstract::forward

(Yaf >=1.0.0)

Yaf_Controller_Abstract::forward转发到另一个动作

说明

public Yaf_Controller_Abstract::forward(string $action, array $paramters = ?): bool
public Yaf_Controller_Abstract::forward(string $controller, string $action, array $paramters = ?): bool
public Yaf_Controller_Abstract::forward(
    string $module,
    string $controller,
    string $action,
    array $paramters = ?
): bool

转发当前处理过程到其他动作。

注意:

此方法不会立即切换到目标操作,而是会在当前流程结束后发生。

参数

module

目标模块名称,如果是 NULL,则采用默认模块名

controller

目标控制器名称

action

目标动作名称

paramters

调用参数

返回值

成功时返回 true, 或者在失败时返回 false

示例

示例 #1 Yaf_Controller_Abstract::forward() 示例

<?php
class IndexController extends Yaf_Controller_Abstract
{
public function
indexAction(){
$logined = $_SESSION["login"];
if (!
$logined) {
$this->forward("login", array("from" => "Index")); // 转发到 login 动作
return FALSE; // 这非常重要,这会结束当前工作流
// 然后告诉 Yaf 不要自动渲染
}

// other processes
}

public function
loginAction() {
echo
"login, redirected from ", $this->_request->getParam("from") , " action";
}
}
?>

以上示例的输出类似于:

login, redirected from Index action

参见

  • Yaf_Request_Abstrace::getParam()
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top