When I was developing countycriminal.com and identityalert.org we ran
into a very similar issue. What we ended up doing was just naming the
components something different than the model's.
With my latest project theeasyapi.com I did the same thing. This time
though I was more aware of the components and had the naming
conventions setup in a way that I can expand the system into new areas
in the future. Right now it's an API where you can access some really
important data that every developer needs access to. In the near
future you will be able to access other API's through our one
integrated API. I'm in the process of building a component for that
as well and will release to the bakery when I've tested it a bit
further.
Take care and hope this helps,
Chad
On Jan 24, 4:20 pm, Miles J <mileswjohn...@gmail.com> wrote:
> I ran into this problem when I had a model and component both named
> "Account". Model gets loaded after so I think it overwrites.
>
> However, I am not sure the Component thing will work as I never tried
> it. It does work for Behaviors, so its worth a shot.
>
> On Jan 24, 12:40 pm, euromark <dereurom...@googlemail.com> wrote:
>
> > so the model has a higher priority for
> > $this->Color than any component with the same name?
>
> > good to know :)
>
> > On 24 Jan., 21:32, Miles J <mileswjohn...@gmail.com> wrote:
>
> > > Just leave them as is, and call the components from the collection
> > > object.
>
> > > $this->Color->find(); // Model
> > > $this->Component->Color->method(); // Component
>
> > > On Jan 24, 7:45 am, euromark <dereurom...@googlemail.com> wrote:
>
> > > > that would actually be a nice and easy way to remove conficts if you
> > > > dont want to rename the class
> > > > on the other hand that would have the same effect - so you could
> > > > rename it right away
>
> > > > maybe it would be more appropriate to call them with their real class
> > > > name
> > > > $this->ColorComponent->
> > > > to delimit them from a "real" model with
> > > > $this->Color->...
>
> > > > usually there are not too many calls to a component anyway (compared
> > > > to model calls)
> > > > and there would be no suprises
> > > > and adding Component is not that much more typing...
>
> > > > On 24 Jan., 11:25, John Andersen <j.andersen...@gmail.com> wrote:
>
> > > > > Just an idea, couldn't a similar solution be as for the models, using
> > > > > a kind of alias when there are more than one relationship between two
> > > > > models.
>
> > > > > Here it would be that a controller or a component can be referred to
> > > > > using an alias.
>
> > > > > [example]
> > > > > class ColorComponent extends ... {
> > > > > var $alias = 'MySplendidColour';
> > > > > ...
>
> > > > > }
>
> > > > > ... other code ...
> > > > > $this->MySpledidColour->someColourMethod(...);
> > > > > ...
> > > > > [/example]
>
> > > > > But it may actually be too complicated to keep track of what is named
> > > > > what and used as what :)
>
> > > > > Enjoy,
> > > > > John
>
> > > > > On Jan 23, 4:27 pm, euromark <dereurom...@googlemail.com> wrote:
>
> > > > > > actually d) does not work for 80% of all components and therefore is
> > > > > > not really working
> > > > > > scatch that
>
> > > > > > b) will never make it^^ and changing the core is not really an option
> > > > > > i guess
>
> > > > > > so its most like either a) or c)
> > > > > > both resulting in 2 groups of components - one with native names and
> > > > > > one with artificially assigned names
>
> > > > > > On 23 Jan., 15:21, euromark <dereurom...@googlemail.com> wrote:
>
> > > > > > > there can be several naming conflicts between models and components if
> > > > > > > you include a new component with an existing model if they have the
> > > > > > > same name inside the controller
>
> > > > > > > example:
> > > > > > > - db table "emails" with model "Email" and "EmailComponent" both
> > > > > > > result in $this->Email in the controller overriding each other causing
> > > > > > > fatal errors.
>
> > > > > > > example:
> > > > > > > - including "ColorComponent" to a project using a "Color" model result
> > > > > > > in $this->Color in the controller
>
> > > > > > > same with "File", "Currency" and so on
>
> > > > > > > what would be the best way to deal with it?
>
> > > > > > > a)
> > > > > > > renaming the components to its "plural" version and update all method
> > > > > > > calls? seems not to be the best choice. all component names usually
> > > > > > > are singular - we would then have some plural and some singular ones.
> > > > > > > getting quite confusing. plus it feels like components should stay
> > > > > > > singular - its kinda awkward if they are not.
>
> > > > > > > b)
> > > > > > > including components with "Component" attached (the real class name)
> > > > > > > instead? $this->ColorComponent and $this->Color would not conflict
> > > > > > > anymore - but this might require a core hack. and although this was
> > > > > > > already pointed out in 1.2 tickets this was not seen as a neccessarity
> > > > > > > from the core team.
> > > > > > > this would require a lot of method call renaming but would probabably
> > > > > > > be the most straightforward and future proof approach. adding new
> > > > > > > components would not result in a farce.
>
> > > > > > > c)
> > > > > > > adding some "fake" attribute to the class name?
> > > > > > > ColorCompComponent extends Object to be able to use it with $this->ColorComp->method() maybe?
>
> > > > > > > Renaming the model or the component might only resolve it temporally -
> > > > > > > until another crash comes up. Renaming either one of them to a totally
> > > > > > > awkward name just to avoid the conflict doesnt really please me,
> > > > > > > either :)
> > > > > > > you wouldnt want to be forced to name the component
> > > > > > > "MyAwesomeColor"(Component) just because you cant use the one that
> > > > > > > would be most appropriate due to some existing db tables and their
> > > > > > > models
>
> > > > > > > d)
> > > > > > > renaming it to a similar name that will probably never exist as a
> > > > > > > model? like
> > > > > > > "Coloring" or "Emailing"? this might not work for all components but
> > > > > > > would fit in the overall framework very well. behaviours are "...able"
> > > > > > > and components then "...ing".
> > > > > > > thats my personal favorite after all.
>
> > > > > > > PS: "color" component as well as the other ones are just exemplary for
> > > > > > > a whole bunch of naming conflicts - in my case
>
> > > > > > > i am interesting what you think
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
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:
Post a Comment