3
votes

I'd like to set as default page some script from views directory, for example \application\views\index.php and delete index.php file from the root of application. IS it possible? (I tried to change value of config['index_page'] to what i would like, but it gives me error that page not found).

Or maybe codeigniter has so strict project structure that i can't do such changes?

2
index.php in root directory is not default page its bootstrap of your application. read few posts like "codeigniter example project" and about "MVC" first - san4o

2 Answers

2
votes

You can't delete index.php file from root directory, instead of that you can remove index.php from the url.

You have to define default controller first, then do follow steps

Have the.htaccess file in the application root directory, along with the index.php file. (Check if the htaccess extension is correct , Bz htaccess.txt did not work for me.)

And Add the following rules to .htaccess file,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]  

Then find the following line in your application/config/config.php file

$config['index_page'] = 'index.php';

Set the variable empty as below.

$config['index_page'] = '';

That's it, it worked for me.

If it doesn't work further try to replace following variable with these parameters ('AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI', and 'ORIG_PATH_INFO') one by one

$config['uri_protocol'] = 'AUTO';
1
votes
$config['index_page'] = '';

will do the trick

from now if you access your site like:

http://mypage.com

the default controller would be called

you can change it in routes.php file in your application/config folder

like:

$route['default_controller'] = "views/index";

Btw. your views.php controller in (application/controllers) should look like somehting like that:

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

class Views extends CI_Controller {

    public function index()
    {

        $data = "Text from controller's index method";
        $this->load->view('myview', $data);

    }

}

And your myview.php in (application/views):

<?php echo $data; ?>