How to avoid this looping when try to reach index()
-
26-06-2021 - |
Pergunta
I'm trying to check if $this->current_user
is set, otherwise redirect to the login page but because Wall is my default route it loops and give me a 500 Internal Server Error, does any have some ideas in how to work with that? I'm using PyroCMS and them use IonAuth.
class Wall extends Public_Controller {
public function __construct() {
parent::__construct();
if (empty($this->current_user)) {
$this->session->set_flashdata('error', 'Debes iniciar sesión para acceder a esta página');
redirect(site_url());
}
}
}
Cheers and thanks in advance
Solução
The redirect() method redirects to a URL. You can use redirect(site_url('login')); as long as you make sure that you have a controller ready with the name 'login'.
If you don't want to use site_url(), you can also hardcode the URL in like:
redirect('http://www.yoursite.com/login');
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow