锂转发请求 [英] Lithium forward request

查看:83
本文介绍了锂转发请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Lithium中的controller redirect()方法执行实际的HTTP重定向.但是,有没有一种方法可以简单地将请求转发到另一个控制器/操作而无需HTTP重定向?

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?

例如,说我想添加一个身份验证层,而不是将用户重定向到"/auth/login"页面,而是呈现登录布局和模板,而不是呈现他们请求的页面的内容.然后,当他们提交表单并进行身份验证时,他们已经在他们请求的页面上. Zend框架与_forward()方法类似.

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.

谢谢!

推荐答案

没有方法,主要是因为您可以用大约两行代码来实现:

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']);
        }
    }
?>

这篇关于锂转发请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆