Sebastian Frohm
Sebastian Frohm

Reputation: 417

Code for Redirection Not Working

I am having some problems with redirection on Phalcon 0.8b.

Here is my code:

<?php
class UsersController extends \Phalcon\Mvc\Controller {
    public function loginAction() {
        if($this->session->get('user')) {
            $this->response->redirect('users/view/');

            exit;
        }
    }
}

Basically, the code checks if the user is logged in, and then redirects them. I am not getting a redirection to happen, however. It just white screens on me. Am I doing something wrong? The documentation hasn't been very helpful.

Thank you!

Upvotes: 2

Views: 3985

Answers (1)

twistedxtra
twistedxtra

Reputation: 2699

The 'exit' is avoiding that the response headers be sent to client, the following must work:

<?php

class UsersController extends \Phalcon\Mvc\Controller {

    public function loginAction() {
        if($this->session->get('user')) {
            return $this->response->redirect('users/view/');            
        }
    }
}

Upvotes: 5

Related Questions