Why does the index() method not recognize the [IC] redirect?

Asked

Viewed 220 times

2

I’m following a course and stopped at a problem that I can’t solve. In this link it is possible to register a user and when finishing the registration he should go to this page but the only thing that happens is a 404 error.

Routes.php

$route['default_controller'] = 'dashboard';
$route['usuario/{:num}'] = "usuario/index/$1";
$route['404_override'] = '';

Php user.

INSERTING IN THE BANK

public function cadastrar()
{
    $data['nome']       = $this->input->post('nome');
    ...

    if( $this->db->insert('usuario', $data) ){
        redirect('usuario/1');
    } else {
        redirect('usuario/2');
    }

}

IS NOT REDIRECTING

public function index($indice=null)
{
    $this->load->view('includes/html_header');
    $this->load->view('includes/menu');
    if($indice==1){
        $data['msg'] = "Usuário foi cadastrado com sucesso";
        $this->load->view("includes/msg_sucesso", $data);
    } elseif ($indice==2) {
        $data['msg'] = "Não foi possível cadastrar o usuário. Tente novamente.";
        $this->load->view("includes/msg_erro", $data);
    }
    $this->load->view('listar_usuario');
    $this->load->view('includes/html_footer');

}

The includes are also correct and as much as they were not, I think it redirects in the same way. Why is it not redirecting, is sending that page pro 404?

1 answer

1

Checks in the config/config.php file whether the value of the base_url key of the $config vector is set correctly according to the url of your site/system:

//Site local
$config['base_url'] = 'http://localhost/';

//Servidor remoto
$config['base_url'] = 'http://meusite.com.br/';

The function redirect CI uses the value configured in $config['base_url'] to generate the url to which the system will be redirected and if it is configured incorrectly the system will be redirected to a page does not exist and thus returning error 404(page not found).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.