I used the manual method you just described for my own Component
factory, a while back. It's not exactly elegant, but I didn't find
that cake provided me much else to build on. I suppose you could
hijack Component::_loadComponents for your purposes, but I've never
done it myself.
I did do things a bit differently in my project, though. This is
probably not the most efficient solution, but it's pretty clean and
got the job done quite well for me.
I created a ComponentFactory component, and subclassed it for each
component "family" I had. This family-specific component factory is
what gets loaded into your controller's $components array. The
factory ran on startup and stored the resulting object as a class
variable. The factory itself used PHP5's __call function to delegate
all method calls to the object. In the end, you name your component
factory whatever the "family" name is, include the component in your
controller's $components array, and the rest is handled
automatically. $this->{$familyName}->doSomething();
For example, AnimalComponent extends FactoryComponent. Set: var
$components = array('Animal'); in your Controller. The factory runs
on startup and sets: $this->obj to a new DogComponent.
FactoryComponent::_loadObj handles all the Component instantiation and
initialization. In your controller, $this->Animal->speak(); would
call the stored DogComponent's speak method via
AnimalComponent::__call.
I hope that gives you a few ideas. I'd be interested to hear what you
come up with.
On Jul 17, 9:09 am, keymaster <[EMAIL PROTECTED]> wrote:
> Looking less positive, I'm afraid.
>
> Since cake tries to instantiate all components in the $components
> array, but an abstract class cannot be instantiated, it doesn't seem
> like there is any straighforward way of using abstract classes within
> cake (short of treating them as vendors).
>
> One kludge might be to leave it in the components folder, but just
> don't put it in the $components array in your controller, then do
> everything manually yourself.
>
> 1. App::import() it,
> 2. instantiate it,
> 3. run the startup() and
> 4. insert it into a class variable inside the controller object, using
> the component name.
>
> Basically you are doing what cake does, but from then on, you can
> access it as you would any component.
>
> Unfortunately that's not much better than putting it in app/vendors,
> and treating it like any other external code.
>
> Any better ideas?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---