3

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?

1
  • 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 Commented Mar 18, 2013 at 13:23

2 Answers 2

2

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';
Sign up to request clarification or add additional context in comments.

8 Comments

You have to make sure that your server has mod_rewrite enabled
Yes, my server has mod_rewrite enabled. Your suggestion about index.php is works, but now i have another problem associated to it. Now i have default controller InterviewController. In index() method of this controller i load addInterview view. So now when i call my site it is loaded addInterview view as a default page. But when i press "save" button which must call saveInterview() method, it doesn't work. It returns 404 error. What i'am doing wrong?
Check to which action you are submitting the form and the url is correct. add a '/' before the url. like this. form_open('/interview/add_interview, $attributes);
I'm calling form_open_multipart('InterviewController/saveInterview');. It is routing to localhost/InterviewController/saveInterview. But there i get 404. If i type myself localhost/index.php/InterviewController/saveInterview, then i get what i need. Seems like i removed index.php from URL of just default page, but not from all pages of site. What do you recommend?
That means localhost/InterviewController/saveInterview does not work. Give me your $config['base_url']
|
1
$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; ?>

5 Comments

Chnge the route also to $route['default_controller'] = "views/index"; if youtr controller file is like: views.php
See updated code in my anser. PLease, let me know if it work or not. Thanks.
There are changes i did: 1. in config.php i have $config['index_page'] = ''; 2. in routes.php i have $route['default_controller'] = "InterviewController"; 3. in my InterviewController i have index() which loads some view script. But it doesn't work
InterviewController is located in /application/controllers directory
Do not even think of doing such.

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.