0

I'm exploring codeigniter. On app startup default controller is changed to load my controller.

Controller properly loads the view and that's fine, so I'm guessing routing works as expected, but when I use (manually type on address bar other method on same controller) same url pattern /controller/method I'm getting 404 error, either view exist.

Do have to change some default routing behavior or something else is problem?

Thanks

user1765862
  • 13,635
  • 28
  • 115
  • 220
  • 1
    You might need an htaccess file. Google for a CodeIgniter htaccess file. – Ayush May 16 '13 at 19:44
  • 1
    @user1765862 : you have to use index.php/controller/method/id unless u use .htaccess to rewrite url . very easy put .htaccess file in docs root ,content of .htaccess can be find in codeigniter user guide – Niladri Das May 16 '13 at 19:57

3 Answers3

2

I dont know if you already removed index.php from your url pattern, assuming that's the case you should type inside browser address field index.php/controller/method. (if you manually type url as you describe)

If you on the other hand do not want to use index.php on every link you can consider to remove that, more info here.

Community
  • 1
  • 1
BobRock
  • 3,477
  • 3
  • 31
  • 48
0

Well this may be the because of index.php file as mentioned above or else if you would like get rid of index.php Kindly include .htaccess file in your application.

 config/config.php - modifiy 
 $config['base_url'] = 'index.php'
 $config['base_url'] = '' // set it to blank

For .htaccess file refer the below code

 RewriteEngine on
 RewriteCond $1 !^(index\.php|images|robots\.txt)
 RewriteRule ^(.*)$ /index.php/$1 [L]
Vinit Kadkol
  • 1,221
  • 13
  • 12
0

follow this

root_folder/.htaccess

to remove index.php in url

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

set base URL

root_folder/application/config/config.php

| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
| The auto-detection mechanism exists only for convenience during
| development and MUST NOT be used in production!
|
| If you need to allow multiple domains, remember that this file is still
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = 'http://[::1]/my-project/';

removing index.php in url, even on request post in form

root_folder/application/config/config.php

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

set default controller, mine is 'home'

root_folder/application/config/routes.php

| controller and method URI segments.
|
| Examples: my-controller/index -> my_controller/index
|       my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'home';

after that, make sure that the all controller file name is capitalize. also a class name.

this is also important mostly when you need to upload in a live server.

root_folder/application/controllers/Home.php

<?php

/**
 * 
 * 
 * @author Lloric Garcia <emorickfighter@gmail.com>
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends MY_Controller {

    public function index() {

    }    

}

then this will be you url

http://[::1]/my-project/home


that is my set up even in live server

all of this came from

https://www.codeigniter.com/userguide3/index.html