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


Messages In This Thread
Non Existent Controllers in a Sub Directory don't fallback to function in default controller - by El Forum - 08-16-2010, 09:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB