繁体   English   中英

重定向到动作/页面LightVC PHP?

[英]Redirect to action/page LightVC PHP?

简而言之,我尝试登录到我的网站并在成功后显示另一个页面。 流程是用户填写表单并提交,我使用jquery $ .post()将数据发布到控制器的actionLogin。 然后在actionLogin中,我验证用户并使用header('dashboard/1')重定向到另一个页面,其中,dashboard是同一控制器中的另一个操作,而1是用户的ID。 我的问题是来自actionDashboard的页面实际上并未呈现。 用户停留在登录页面上,而我在jquery $ .post响应中仅获得仪表板的视图代码,因此在登录时可以在控制台中看到它。 有任何想法吗? 我正在使用LightVC 这是下面的简化代码:

main.js

$.post('/default/ajaxLogin', {
    email: $('#email').val(), 
    pass: $('#pass').val()
}, function(response) {
    console.log(response);
});

default.php(控制器)

//we start here where we can use main.js
public function actionIndex() 
{
    $this->setLayout('default');
    $this->setLayoutVar('pageTitle', 'Home');
}    
public function actionAjaxLogin() 
{ 
    //do some login verification
    //ok login successful, now redirect to dashboard
    header('Location: /dashboard/1');
}
public function actionDashboard($userId)
{
    $this->setLayout('dashboard');
    $this->setLayoutVar('pageTitle', 'Dashboard');
    $this->loadView('default/dashboard');
}

就像我说的那样,由于某种原因,页面实际上并未呈现。 我只在main.js的响应中得到了html。 我从涉及Yii和Laravel的其他问题中看到了很多想法,但与我的特定问题或LightVC框架无关。 有任何想法吗?

谢谢!

我感觉就像您在使用Ajax帖子并期望将其重定向到其他页面一样,这似乎是不可能的,因为ajax请求期望返回响应并在客户端的回调中进行处理。

我认为您应该尝试删除代码的标题行,而仅呈现仪表板布局。

您可以尝试下面的修改代码,看看

//we start here where we can use main.js
public function actionIndex() 
{
    $this->setLayout('default');
    $this->setLayoutVar('pageTitle', 'Home');
}    
public function actionAjaxLogin() 
{ 
    //do some login verification
    //ok login successful, now redirect to dashboard
    $this->actionDashboard(1);
    //header('Location: /dashboard/1');
}
public function actionDashboard($userId)
{
    $this->setLayout('dashboard');
    $this->setLayoutVar('pageTitle', 'Dashboard');
    $this->loadView('default/dashboard');
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM