_forward()公共方法是用来呼叫actions,这可以使我们更容易的在action之间进行传值。
_forward($action, $controller = null, $module = null, array $params = null)
我们看到_forward()包含四部分,其中三部份是可选的:
- $action (string required): The action to call.
- $controller (string optional): The controller the action is in.
- $module (string optional): The module the controller is in.
- $params (array optional): User parameters to send with the request.
例如:
我们新建一个controller名为 contact:

在index controller里做如下更改:

打开 http://127.0.0.1:8080/index/index 时,会看到:

_redirect() utility method
跟_forward()功能相反。
The _redirect() utility method is in a way the opposite to _forward().
Where _forward() calls an action within the same request, _redirect() performs an HTTP redirect creating a new request.
redirect() accepts the following arguments:
- $url (string required): The URL to redirect to
- $options (Array Optional)
- exit (Boolean): Whether to exit straight away, or not
- prependBase (Boolean): Prepend the base URL, or not
- code (String): The HTTP code to use
0 评论:
Post a Comment