The controller redirect() method in Lithium does an actual HTTP redirect. But is there a method to simply forward a request to another controller/action without an HTTP redirect?
For example, say I want to add an authentication layer and rather than redirecting the user to a "/auth/login" page, the login layout and template get rendered rather than the content for the page they requested. Then, when they submit the form and they authenticate, they're already on the page they requested. Zend framework has something similar with a _forward() method.
Thanks!
There's no method, mostly because you can do it in about two lines of code:
<?php
namespace my_app\controllers;
use lithium\core\Libraries;
class PostsController extends \lithium\action\Controller {
public function index() {
$forward = Libraries::instance("controllers", "Auth", [
'request' => $this->request
]);
return $forward($this->request, ['action' => 'login']);
}
}
?>
来源:https://stackoverflow.com/questions/14464643/lithium-forward-request