What I'm trying to do:
I have a plugin which includes a component that I want to be available
to controllers outside the plugin.  I want the component to be able to
shortcut a controller's view rendering like the cakeError method
does.  Why not use standard cake error handling?  I found this:

http://bakery.cakephp.org/articles/view/custom-error-handing-for-plugins

The problem: a controller in the base app directory will not recognize
the plugin's error.  So I ended up coming up with the workaround below
to interrupt the controller action and replace the controller's
default view with a view file from the plugin.  Basically, the problem
it solves is rendering a view based on an absolute path -- something
which the file argument in the render method does not do.

My question: is there a cleaner way to accomplish this?

The code for the plugin component's error-rendering method:

    function cake_error($ParamList=array())
    {
        $view_dir = dirname(dirname(dirname(__FILE__))) . DS .
'views' . DS;
        $render_file = '/error/default';

        # defaults
        $header = 'Page Unavailable';
        $message = 'You are not authorized to view this page.';
        $code = 200;
        extract($ParamList, EXTR_OVERWRITE);

        # header (does this work?)
        $this->Ctrl->header($code);

        # set message and $header
        $this->Ctrl->set('header', $header);
        $this->Ctrl->set('message', $message);

        # must hack the view path here to add plugin view dir because
I can't
        # find any other way to set an absolute path for the view path
        $ViewPathList = Configure::read('viewPaths') + array
( $view_dir );
        Configure::write('viewPaths', $ViewPathList);

        # mimics error output to shortcut view output by the
controller action
        $this->Ctrl->render(null, null, $render_file);
        $this->Ctrl->afterFilter();
        echo $this->Ctrl->output;
        $this->Ctrl->_stop();
    }

The view file will be in:
app/plugins/plugin_name/views/error/default.ctp

Thanks,
Tom
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to