[Solar-talk] Hacking with actionError()

Rodrigo Moraes rodrigo.moraes at gmail.com
Fri Jan 19 10:27:25 PST 2007


This is just something funny I discovered: you can call the default
controller using different paths by hacking ActionError(), now that it
the error is called from the default app when a controller is not
found:

Example:

You access http://localhost/myfakecontroller (there is not such app).

* old behavior: simple text with 'page not found'
* new behavior: call default app's actionError() method.

Then, the hack:

    public function actionError()
    {
        $uri = Solar::factory('Solar_Uri_Action');

        $fake_controllers = array(
            'myfakecontroller' => 'myaction',
        );

        if(isset($uri->path[0])) {
            foreach($fake_controllers as $path => $action) {
                if($uri->path[0] == $path) {
                    return $this->_forward($action);
                }
            }
        }
    }

Now, when you access '/myfakecontroller', it will load the default app
and the 'myaction' action. Other paths not listed in the array will
just proceed with the error.

A hack, yes, but maybe it has some uses.

rodrigo


More information about the solar-talk mailing list