Tuesday, April 5, 2011

creating a non-component for my controller

It appears to me that Compent is designed so that you can only have
one instance of any given type per controller per request. What if I
want to use a class in one of my controllers that doesn't neatly fit
the pattern of a Component, because I may want to create more than one
instance per request?

In other words, I'd like to instantiate it in my code like this:

$my_instance = new MyClass($some_arg);
$another_instance = new MyClass($another_arg);, ...

If I define it in app/libs/my_class.php, can I still load it with
App::import()? I tried it but couldn't figure out what arguments to
use in import()? http://api13.cakephp.org/class/app#method-Appimport.
I had to fall back on require_once(). I'm sure there is a more
standard way to accomplish this, but I'm still learning Cake.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

No comments: