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

2

I'm following a course and stopped at a problem I can not solve. In this link it is possible to register a user and when finishing the registration he should go to this one 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'] = '';

User.php

  

TRE 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');
    }

}
  

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 even though they were not, I think it redirects in the same way. Because it will not be redirecting, you are sending this page pro 404?

    
asked by anonymous 24.10.2015 / 20:39

1 answer

1

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

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

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

The redirect function of the 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).

    
26.10.2015 / 20:04