Welcome Guest, Not a member yet? Register   Sign In
Extending the CI_Router
#1

[eluser]Maglok[/eluser]
I have an application running on 1.7.3 that I am updating to 2.0.0.

I had extended the Router that any page not found was to be redirected to a controller called 'content' and used a a parameter there.

Example: somewhere.com/page1 would lead to somewhere.com/content/page1 (but show somewhere.com/page1).

This worked masterfully. Smile Now I am trying to update to the 2.0 Router and I am combining the code of the new one with the tweak I need. It doesn't seem to route the way I want yet.

This is the code in 2.0.0:
Code:
// If we've gotten this far it means that the URI does not correlate to a valid
        // controller class.  We will now see if there is an override
        if (!empty($this->routes['404_override']))
        {
            $x = explode('/', $this->routes['404_override']);

            $this->set_class($x[0]);
            $this->set_method(isset($x[1]) ? $x[1] : 'index');

            return $x;
        }


        // Nothing else to do at this point but show a 404
        show_404($segments[0]);

And this was the code of my modified router in 1.7.3:
Code:
// Not a sub-dir or controller, now go to content and try there
        $this->set_class('content');
        $this->set_method('index');
        // return array('content', 'static', $segments[0]);
        return array();

        // Can't find the requested controller...
        //show_404($segments[0]);

Please note that I also intend to use the new error controller functionality. (At the moment it is doing the same with a long workaround).

Anyhow once I add in the 2.0 stuff I get the following error:
Code:
Fatal error: Class 'CI_Controller' not found in /home/content/85/5336885/html/test/system/core/CodeIgniter.php on line 210

Which seems to point to this line in the core classes:
Code:
function &get;_instance()
    {
        return CI_Controller::get_instance();
    }

I would think it have something to do with what I extend. I extend CI_Router.

Anyone got an idea?

EDIT: And the class is called MY_Router. I am unsure if that is ok with the 'new' 2.0.0 dir (it is in the application/core dir).
#2

[eluser]Maglok[/eluser]
Apologies for the dual post.

I have found out that the application flow chart seems to suggest that the Controller is loaded after the Router (duh), but that also means CI won't be available. Somewhere something is going wrong trying to load around that.
#3

[eluser]Unknown[/eluser]
Sorry if this isn't much help to you... but can't you get most of this functionality using something like this in routes.php?


$route['(:any)'] = "content/index/$1";




Theme © iAndrew 2016 - Forum software by © MyBB