I think the point about Cake as it stands is that a model will return
it's data and any data associated with it as a nested array, which may
actually help in what you want.
If you defined your own Project and Issue interfaces with interfaces
that extend these (LocalProject extends Project, Complaint extends Issue
), then any of your models can implement them since you have the
generated source for those models. 2 Project and Issue behaviour classes
could then give concrete implementations of the 2 interfaces...
So your model definition would become:
class LocalModel extends AppModel implements ProjectInterface,
IssueInterface {
public $actsAs = array( 'LocalProject', 'Complaint' );
...
}
class SoftwareModel extends AppModel implements ProjectInterface,
IssueInterface {
public $actsAs = array( 'SoftwareProject', 'BugReport' );
...
}
Then your factory would just need to create the right model at runtime
and return it to a controller. The controller is happy since it is
getting a Model and your software is happy since the Model is also a
Project and Issue instance.
Just some thoughts :) But I may have missed the point.
Steve (Ratty)
On 01/06/12 20:04, elitalon wrote:
Hi,
I've been reading a couple of articles about implementing factory
patterns in CakePHP but I can't find a hint to solve my actual
problem. There is one that tries to mimic these kind of patterns using
behaviors
<http://mamchenkov.net/wordpress/2010/02/17/cakephp-building-factories-with-models-and-behaviors/>,
but it's not exactly what I'm looking for.
I am developing an application that implements several types of issues
management: customer complaints, software bugs, medical reviews, etc.
The core is built around a common set of models: Brand, Customer,
Project and Issues. A customer can sign up for many brands. What
varies from brand to brand are Project and Issue, so that there is a
LocalProject and its ComplaintIssue, a SoftwareProject and its
BugIssue, a MedicalCenterProject and its ReviewIssue, etc.
Factory patterns suggest to implement to an interface (i.e. using
Project and Issue classes) and make object instantiation at runtime.
Doing that it's relatively easy in controllers, e.g you can
instantiate $this->Project in ProjectsController according to runtime
conditions.
But things get complicated when a hierarchy of relationships is
present, since model construction is made "behind the scenes" in deep
associations. Is there a way to define a factory method in CakePHP
that can be used to decide which concrete class should be used at runtime?
Thanks!!!
--
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
[email protected] For more options, visit this
group at http://groups.google.com/group/cake-php
--
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
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php