We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Can Phalcon's redirect method bring page jump to another page?

due to the admin page need roles to view,so,i have to set some session,and get variable from session,but it will take me some errors when i have not login on the page

so,i use $this->response->redirect() to bring me to the login page first,but, infact,it will parse the template first and take me some wrong lines,for this,i try to use "hader('location:/login')" and successfully to jump to the login page,so i want to know,whether the $this->resposne->redirect support this way or not

thanks!



33.8k

You mean to grant access to the login or the aplication if the user isn't/is logged?

Sorry, I don't really get what do you want.



10.3k
edited Aug '14

Sorry , my english is so so.

I mean to redirect another url like

header("location:url");

This is my controller called AdminController:

<?php
namespace Brand\Library;

class AdminController extends \Phalcon\MVC\Controller
{
    public function onConstruct()
    {
        //var_dump(is_null($this->session->get('auth')));exit;
        if(is_null($this->session->get('auth'))){
            //$this->response->redirect('admin/login');
            header('location:/admin/login');
            exit;
        }
    }
}

In fact, I want to use $this->response->redirect instead of header, but it does not work

think, whether phalcon offer another method to realize this or not!

thanks



10.3k
Accepted
answer

thanks all guys,i have found how to solve the problem,i have to use $this->view->disable() before $this->response->redirect(),like this:

<?php
namespace Brand\Library\Controllers;

class AdminController extends \Phalcon\MVC\Controller
{
    public function onConstruct()
    {
        if(is_null($this->session->get('auth'))){
            $this->view->disable();
            $this->response->redirect('admin/login');
        }
    }
}