Welcome Guest, Not a member yet? Register   Sign In
redirect a user from a main controller
#1

(This post was last modified: 07-13-2021, 03:13 PM by Z4K7.)

I am created a login project
I am presenting a difficulty since at the time of the user entering the login, it is not redirecting to the web that I want but it remains in the login validator
the file structures is yes

PHP Code:
<?php 

namespace App\Controllers;


class 
Admin_Controller extends BaseController
{
 


 public function 
ingresar_panal()
 {

 return 
redirect()->to('panel');

 }

}
?>


this is my main controller where I would give the whole body of the more controllers

this is the login controller

PHP Code:
<?php

namespace App\Controllers\admin;
use 
App\Controllers\Admin_Controller;

class 
Login extends Admin_Controller


 public function 
index()
 {

 echo 
view('admin/login');
 
 }
 public function 
validacion()
 {
 
$this->ingresar_panal();
}
The login is validated without any problembut when you click on the login buttonit is not redirecting where you would have to enter if not only it remains in login


ya valide desde la configuración de Router 
PHP Code:
$routes->get('/''Login::index');
$routes->Post('login''Login::validacion');
$routes->get('panel''Panel::index'); 

It could help me what is the failure since if I place the redirection from the following way if it works


PHP Code:
<?php

namespace App\Controllers\admin;
use 
App\Controllers\Admin_Controller;

class 
Login extends Admin_Controller
{

public function 
index()
{

echo 
view('admin/login');

}
public function 
validacion()
{
return 
redirect()->to('panel');





and it is addressed where I want to but I don't understand if I do it from the main controller and call that one, it works, it is not working, it could help me or clarify what is happening

Thank you
Reply
#2

(This post was last modified: 07-14-2021, 02:35 AM by paliz.)

Use authentication filter to check whether use log in or not

https://codeigniter4.github.io/userguide...lters.html

Before function check user status

You can not repeat code for every
Ctl once for all
Enlightenment  Is  Freedom
Reply
#3

I've got to agree with @paliz on this one, the Filter is the best choice to accomplish this. You can always exclude certain pages to bypass the authentication part.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB