Lithium forward request

空扰寡人 提交于 2019-12-05 05:48:44

问题


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!


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!