Welcome Guest, Not a member yet? Register   Sign In
Default Function ( index() ) for Controller Not Found
#1

[eluser]beneck[/eluser]
I have been continually having a problem with the index() method not being found even thought it is present. I must explicitly type the class and function name in.

In the Code Igniter Manual it says this....

Quote:example.com/index.php/blog

Functions
In the above example the function name is index(). The "index" function is always loaded by default if the second segment of the URI is empty.

However, I am having trouble getting this to work. I have a class named "Ben"

Code:
class Ben extends CI_Controller {
  
public function index()
{

  echo "hello world";
  

}
}

When I type in

mysite.com/index.php/ben/index it works just fine. However, per the manual, if I try it without the index

mysite.com/index.php/ben it does not work and I get a "Page Not Found" error.


My config file looks like this.

Code:
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
| (removed excess comments for brevity)
|
*/
$config['base_url'] = '';

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
| (removed excess comments for brevity)
|
*/
$config['index_page'] = 'index.php';

/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
| (removed excess comments for brevity)
|
*/
$config['uri_protocol'] = 'AUTO';

Any thoughts on why this isn't working?

PLEASE NOTE
I know I can get this ONE INSTANCE to work with a custom route. However, the problem is figuring out why the built in functionality is not working right. This is a problem as NONE of my controllers index functions are being found and I don't want to have to make dozens of custom routes just to solve a problem that is supposed to be built into the software in the first place.

I would appreciate any help on what might be going on.
#2

[eluser]beneck[/eluser]
SOLVED

I had a thought after I posted this and I can't delete this topic now. It was user error.

I had made a custom router MY_Router.php (which was fine). However, prior to that I edited the core Router.php file to try and convert all hyphens to underscores. I broke the Router file.

I just copied a fresh download (making sure it was the same version) over the old file and it fixed the problem.

Also, I solved my hyphen to underscore problem with some HTACCESS code.

Live and learn.




Theme © iAndrew 2016 - Forum software by © MyBB