Installing the CodeIgniter was very easy and straightforward. You just need to download all the CodeIgniter files in a .zip format and save it to your web location under your apache server.

Extract the downloaded files to a directory. And just run it in the web browser like http://localhost/your_directory. Now you will see,

 

Remove index.php, from the slug

Before this, lets add sample method to the default controller.

Open application/controller/Welcome.php, in your code editor, right now you can see the default method. Under it write a new method,

public  function test_method() {
      echo "This is test method";
}

To access any controller’s method in the browser, you need to run it as http://localhost/test_dir/<controller_name>/<method>, ie, http://localhost/test_dir/welcome/test_method. But it will throw the error.

To access it, you need to run http://localhost/test_dir/index.php/welcome/test_method in the browser. It looks weird isnt’t it? when the slug contains index.php in it.

in the browser. It looks weird isnt’t it? when the slug contains index.php in it.

So, lets remove it now. For this, 2 steps required

Step 1: Create a .htaccess fild in the root directory with the below code,


RewriteEngine on 
RewriteBase /your_root_directory_name 
RewriteCond $1 !^(index.php|resources|robots.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Step 2: Under application/config/config.php

change, 
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';

change
$config['uri_protocol'] = 'AUTO'; 
to 
$config['uri_protocol'] = 'REQUEST_URI';

Now save the file, and run the http://localhost/test_dir/welcome/test_method. you can see text “This is test method” in your browser.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *