Saturday, November 1, 2008

Re: Instantiating a controller


I ve been trying to find a way to instantiace a controller as one
would do outside cake. That is, i would like to be able to call:

$s = new StatisticsController();

I think the following should do the job -

App::import('Controller', 'YourController');
$controller =& ClassRegistry::init('YourController');

Thanks

On Sat, Nov 1, 2008 at 9:53 PM, jkritikos <jkritikos@gmail.com> wrote:

hi there,

I ve been trying to find a way to instantiace a controller as one
would do outside cake. That is, i would like to be able to call:

$s = new StatisticsController();

in my views, or anywhere else. I know that this can be done using the
requestAction approach but this is such an overkill for a simple
method invocation (since it actually performs an HTTP request,
dispatches it as all other requests in cake, and then ends up invoking
the appropriate function/controller. The error i m getting is related
to the classpath, do i need to use require_once or some other
importing mechanism? Alternatively, is there a way to invoke a
controller method, without the underlying http request?

thanks guys,

jason




--
Anupom Syam
http://syamantics.com/

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

No comments: