Welcome Guest, Not a member yet? Register   Sign In
Default Controller
#1

[eluser]kenjis[/eluser]
If you access to
http://localhost/index.php

you can see controllers/welcome.php.

And if you access to
http://localhost/index.php/hoge (hoge is a empty directory)

also you see controllers/welcome.php.

Is this the specification of default controller?


I expect:

When I access to
http://localhost/index.php/hoge (hoge is a directory)

I see controllers/hoge/welcome.php (if exsits) or 404 Page Not Found.
#2

[eluser]xwero[/eluser]
Do ypu have a catch all routing like
Code:
$route['(.+)'] = 'welcome';
Maybe that is why you don't get the expected page
#3

[eluser]garymardell[/eluser]
I don't know why you would assume the default controller in the directory should be welcome everytime. Currently it will look for hoge controller and then index function. If that isn't found then the sub directory but without another parameter in the url it wont know what controller in that directory. I cannot explain however the absence of the 404 error.

By any change are you using htaccess to remove the index.php and have this section

Code:
<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

That will cause all 404s to get routed to index.php
You could change this to reflect a different page.
#4

[eluser]kenjis[/eluser]
[quote author="xwero" date="1212932748"]Do ypu have a catch all routing like
Code:
$route['(.+)'] = 'welcome';
Maybe that is why you don't get the expected page[/quote]

Thank you for you comment.

I've checked routes.conf, and I found there is no additional routing.

routes.conf:
Code:
$route['default_controller'] = "welcome";
$route['scaffolding_trigger'] = "";
#5

[eluser]kenjis[/eluser]
[quote author="gazza" date="1212974440"]I don't know why you would assume the default controller in the directory should be welcome everytime. Currently it will look for hoge controller and then index function. If that isn't found then the sub directory but without another parameter in the url it wont know what controller in that directory. I cannot explain however the absence of the 404 error.
[/quote]

You're right, and I expect CI to assume the default controller in a sub directory is 'subdir/welcome' (of course you can change 'welcome' in routes.conf).

Because I want to use shortest URI.

In the current spec, most shortest URL using sub directory is like:
Code:
http://example.com/subdir/welcome

If default controller is the controller in sub directory, I can remove
welcome and URL will be like:
Code:
http://example.com/subdir/

And the current spec is not intuitive. If URL is including sub directory, most people expect controllers in sub directory, doesn't they? But CI returns the controller in top directory.
#6

[eluser]Michael Wales[/eluser]
Quote:And the current spec is not intuitive. If URL is including sub directory, most people expect controllers in sub directory, doesn’t they?
No... we read the user guide.

CI supports Controllers in a subdirectory but it is by-far not the most popular feature, nor the standard of which most developers aim.

Break yourself away from the thought that the controller and method names create your URL - they don't. Controllers and methods have absolutely nothing to do with your URL. Develop these names pragmatically.

For instance - I want to show a user's profile. Obviously, I'll call my method profile and the class users but I don't want people to have to use domain.com/users/profile/walesmd to get to my profile, do I? That's hideous - so I route for domain.com/walesmd

Another example:
Recreating Wordpress in CodeIgniter, you could access the index method of the dashboard class by visiting domain.com/wp-admin

Subdirectories should only be used for organizational purposes - not to try and trick CI into using prettier URLs.
#7

[eluser]kenjis[/eluser]
[quote author="Kenji @ CodeIgniter Users Group in Japan" date="1212981308"]
In the current spec, most shortest URL using sub directory is like:
Code:
http://example.com/subdir/welcome

If default controller is the controller in sub directory, I can remove
welcome and URL will be like:
Code:
http://example.com/subdir/
[/quote]

I was wrong. The above is my misunderstanding.
Thank you, Michael.
#8

[eluser]kunitsuji From Japan[/eluser]
Hello of you
I cannot explain well because I cannot speak English.

Example.
$route['default_controller'] = "welcome";
controllers/welcome.php ==> http://domain.com/index.php ==> welcome (OK)
controllers/foo.php ==> http://domain.com/index.php/foo ==> foo (OK)
http://domain.com/index.php/foe ==> 404 not found (OK)
controllers/subdir/foe.php ==> http://domain.com/index.php/subdir/foe/ ==> foe (OK)
http://domain.com/index.php/subdir/foo/ ==> welcome (?)
http://domain.com/index.php/subdir/bar/ ==> 404 not found(OK)

When thinking about the example
If it becomes 404 when the one that doesn't exist in the subdirectory is
specified ,
I thought that when only the subdirectory was specified to 404 usual.
#9

[eluser]Chicken's Egg[/eluser]
[quote author="Michael Wales" date="1213004583"]
Break yourself away from the thought that the controller and method names create your URL - they don't. Controllers and methods have absolutely nothing to do with your URL. Develop these names pragmatically.
[/quote]
Could you please explain this a little bit more to me or give some hints for further reading? If I read the user guide I get the idea that they do have something to do with each other as well. For example: www.mydomain/module/function/variable/.

[quote author="Michael Wales" date="1213004583"]
That's hideous - so I route for domain.com/walesmd
[/quote]
Doesn't that suppose that you <i>know</i> there is a user called walesmd? How should the code know for example that the url domain.com/news is not a user profile, but a question for the most recent newsposts on your website?




Theme © iAndrew 2016 - Forum software by © MyBB