Welcome Guest, Not a member yet? Register   Sign In
Non Existent Controllers in a Sub Directory don't fallback to function in default controller
#1

[eluser]ptrippett[/eluser]
in this example $routes['default_controller'] = 'default_controller'

If I have the following directory structure

Code:
controllers/
    posts/
        tags.php
        default_controller.php

http://site.com/posts/tags loads the tags.php controller but the a request to http://site.com/posts/delete retrunes a 404 not found even if the function is defined in the default_controller.php. CI is not falling back to the default controller before decided that the file can not be found.

This is an easy fix in Router.php line 215
Code:
// Does the requested controller exist in the sub-folder?
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
                {
                    array_unshift($segments, $this->default_controller);
                    return $segments;
                    //show_404($this->fetch_directory().$segments[0]);
                }

Why is this beneficial? You may want to use a subdirectory to segment code but also keep general functions under /posts. as in the example above move all tag related functions into tag.php for /posts/tags/[create|delete|view] but maintain /posts/[create|delete|view]
without having to prefix these end points with /posts/[addTag|deleteTag|viewTag] etc
#2

[eluser]mddd[/eluser]
I don't agree. Making it work this way is inconsistent. You can shouldn't be able to call a method without specifying the controller.
The way you reason, calling www.example.com/foo could mean two things: the index method of the foo controller, or the foo method of the default controller.
'Default controller' is supposed to only kick in when the given path leaves the controller empty (as in www.example.com, or www.example.com/posts if posts is a folder).
#3

[eluser]ptrippett[/eluser]
It could be in two places yes but without this fix details to the inability to send parameters to the index function you end up with a URL of. HTTP://site.com/delete/delete/123 or http://site.com/posts/view/all and even inthe ci instaance we have duplicate possibiilities posts.PHP posts/default_controller.PHP:index() so one more for the sake of completeness is not going to hurt Wink




Theme © iAndrew 2016 - Forum software by © MyBB