1

I'm facing a little problem right now with CodeIgniter...

I have the following file :

applications/controllers/home/entretiens.php

Which looks like this :

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Entretiens extends CI_Controller
{
    public function index()
    {
        if($this->session->userdata('logged_in'))
        {
             $data['page'] = "entretiens";
             $session_data = $this->session->userdata('logged_in');
             $data['prenom'] = $session_data['prenom'];
             $this->load->model("Entretiens_model");
             $data['entretiens'] = $this->Entretiens_model->getAllEntretiens($session_data['id']);
             $data['main_content'] = 'home/entretiens_view.php';
             $this->load->template('entretiens_view', $data);
        }
        else
        {
            //If no session, redirect to login page
            redirect('home/login', 'refresh');
        }
    }

    public function ajouter()
    {
        echo 'Test';
    }
}

?>

If I go with my browser on : myurl/entretiens I get the right page (the index method of the controller "entretiens"), but if I go to myurl/entretiens/ajouter all I get is a 404 from CodeIgniter.

Here's my routes file :

$route['default_controller'] = "home/index_controller";
$route['login'] = "home/login_controller";
$route['user'] = "home/user_controller";
$route['entretiens'] = "home/entretiens";
$route['404_override'] = '';

And the config.php (well, the interesting parts) :

$config['base_url'] = 'http://dev.hinsolite.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

And my .htaccess :

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]

(This problem is on all the controlers, and not only entretiens...

1 Answer 1

1

Change the relevant line in your routes.php as follows:

$route["entretiens(.*)"] = "home/entretiens$1";

This treats as wildcard, everything after entretiens will be passed to home/entretiens.

Sign up to request clarification or add additional context in comments.

1 Comment

Worked great ! Thanks for the help !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.