Welcome Guest, Not a member yet? Register   Sign In
Cannot set controller in subdirectory as default controller
#1

[eluser]TheFuzzy0ne[/eluser]
Hi everyone.

First I'd like to congratulate everyone involved with the project. I've spent way too much time in the past trying to figure out the best way to do things with PHP, and could never really decide on a single solution. Now it all seems to have been done for me. All I need to do is stick some building blocks together, and hey presto! The MVC approach has been confusing me for some time now, and finally after reading through the entire documentation for CI, it's all become somewhat clearer.

The standalone documentation is superb - as is the in-script documentation, and the code is crystal clear - not to mention the screencasts. I now have a completely reborn approach towards PHP programming, and now, my hair is actually starting to grow back again, so many thanks (because it's really cold without it)!

Onto business...

I am trying to set my default controller and I keep getting a 404 error. The path of the file I want to use as the default controller (from the Web root) is:

Code:
/controllers/main/main.php

The config file has been set to:
Code:
$route['default_controller'] = "main/main";

But this doesn't work.

I've tried guessing, and using:

"main"
"main.main"
"main/main.php"

and still I've got nowhere. I can call the main.php controller via www.mysite.com/index.php/main/ without any problems. Is this a bug, or am I just being noobish?

I'd really appreciate any help anyone may have to offer.

Many thanks in advance.

Daz.
#2

[eluser]TheFuzzy0ne[/eluser]
Sorry guys, I'm bumping this because I can't get started on my project until I figure out where I'm going wrong.
#3

[eluser]gtech[/eluser]
does this thread help

[url="http://ellislab.com/forums/viewthread/63125/"]http://ellislab.com/forums/viewthread/63125/[/url]
#4

[eluser]TheFuzzy0ne[/eluser]
[quote author="gtech" date="1209228728"]does this thread help

[url="http://ellislab.com/forums/viewthread/63125/"]http://ellislab.com/forums/viewthread/63125/[/url][/quote]

Yes, it does help quite a bit. The only trouble is that I keep screwing up the inserts somehow. Is it possible to have the entire file as it would be edited? I'm not sure where I'm going wrong. Perhaps I am removing/adding blank lines when I shouldn't.

Many thanks.
#5

[eluser]gtech[/eluser]
I am sorry I don't know, I just found it after searching the forums. I am guessing the router file in the example is slightly older and you might need to do a bit of trial and error.
#6

[eluser]TheFuzzy0ne[/eluser]
[quote author="gtech" date="1209230989"]I am sorry I don't know, I just found it after searching the forums. I am guessing the router file in the example is slightly older and you might need to do a bit of trial and error.[/quote]

OK, that shouldn't be too much of a problem. I've put it in as a feature request, as I don't understand why it didn't work like that from the start. I'm quite sure I'm not the only one who would like it to work like that.

Thanks for your help.
#7

[eluser]gtech[/eluser]
have you looked at HMVC?
[url="http://codeigniter.com/wiki/Modular_Extensions_-_HMVC/"]HMVC Link[/url]

it does not fix your problem but might be of interest to you.

matchbox is another one.
#8

[eluser]TheFuzzy0ne[/eluser]
[quote author="gtech" date="1209233144"]have you looked at HMVC?
[url="http://codeigniter.com/wiki/Modular_Extensions_-_HMVC/"]HMVC Link[/url]

it does not fix your problem but might be of interest to you.

matchbox is another one.[/quote]

Hi. I've come up with my own smaller hack. I'm not sure if it will be frowned on with regards to validity, but it is very small and quite direct. I edited the /system/codeigniter/Codeigniter.php file, and added a little piece of code at line 165.

Code:
...

$class  = $RTR->fetch_class();
$method = $RTR->fetch_method();

// This is a tiny hack that will allow you to have your default
// controller set to a controller residing in a subdiirectory.

# START OF UGLY HACK
$class = explode('/', $class);
$class = $class[sizeof($class)-1];
#END OF UGLY HACK

if ( ! class_exists($class)
    OR $method == 'controller'
    OR substr($method, 0, 1) == '_'
    OR in_array($method, get_class_methods('Controller'), TRUE)
    )
{
    show_404();
}

...

It seems to work for me. I'd appreciate some input on just how ugly it is.

EDIT: Perhaps it would be better off inside of the $RTR->fetch_class() method?
#9

[eluser]wiredesignz[/eluser]
Hacks to the core are not really recommended, You might look into extending the core Router.php library by creating application/libraries/MY_Router.php copying the methods you wish to change from the original file and making your changes in there somewhere.
#10

[eluser]TheFuzzy0ne[/eluser]
[quote author="wiredesignz" date="1209240003"]Hacks to the core are not really recommended, You might look into extending the core Router.php library by creating application/libraries/MY_Router.php copying the methods you wish to change from the original file and making your changes in there somewhere.[/quote]

You're totally right. I should have figured out what I needed changing in the Router.php file, and just overridden the appropriate methods.

I am interested to know whether it would be a worthy submission as a requested feature for CI. This may have been how it was meant to work in the first place, and it could just be a bug, I'm not sure.

However, if it is a bug, it's certainly nothing critical. IMHO opinion, it was something that was implemented and perhaps wasn't tested.




Theme © iAndrew 2016 - Forum software by © MyBB