gwoo,

Sorry to keep this off topic, but the matter of best practices and
proper uses of the var $uses and loadModel (and now ClassRegistry) is
something that has eluded me for quite some time. As indicated by
posts to this thread, I seem to be not alone on this.

What (little) I do know is that it's always better to go through
existing association where ever possible, instead of always relying on
using var $uses (i.e. $this->user->posts->read, instead $this->posts-
>read when in the UsersController). In any other case where this
technique doesn't fit, use the var $uses. Simple enough to understand,
but apparently, maybe not the best or most efficient solution. This
simple practice has kept me from using loadModel, since I didn't fully
understand when and why to use it (again, I know very little). It
seems to me that it's there for performance tweaking, and until now,
I've been heeding Chris Hartjes's advice on "just build it, damn
it"...worry about performance issues if and when they arise. Well, I
think now is the time for me to at least get this part straight as it
looks like it should be easy enough to follow some best practices
*before* possibly creating some performance issues.

I'll add that I've been learning and developing in Cake, while
following this newsgroup here for many months now, and have to say
that this is the first time I've heard of the ClassRegistry. After
searching the group, I see that's it's been talked about a few times,
but it seems to be in more advanced uses. Searching the core, I see
that's it's used by the Cake internals, which is why I'm hesitant to
start messing with it without any direction first (which could create
more problems than I'm solving).

I tend to learn by example, so can someone show me an example of using
the ClassRegistry in the context of avoiding using var $uses or
loadModel? What are the pitfalls, if any, with using this technique
(other than perhaps confusing other Cake noobs)?

Thanks in advance on this one. I'm sure clarification on this issue
will be helpful to many. And maybe this discussion should be continued
in a new thread.

NOSLOW

On Jul 30, 6:09 pm, gwoo <[EMAIL PROTECTED]> wrote:
> There are two reasons to avoid $uses and loadModel in your code.
>
> 1. performance:
> Extra memory will be consummed if you have var $uses and the
> association in your model.
> loadModel simply checks if the class exists and includes it if it does
> not, so the overhead here is minimal. But then you need to create the
> instance so memory is increased. If you go this route, use the
> ClassRegistry. By using the registry when you need to gain access to
> an object you can be assured that you are not adding any extra
> overhead.
>
> 2. maintainability
> everyone knows we are concerned with maintainable code. We provide var
> $uses for the exceptions to the rule (ie: contact form, search, etc)
> These are cases where there is generally no model for that controller
> and so there is a need to override the default behavior. On the other
> hand, loadModel can create spaghetti plain and simple. Using loadModel
> can be likened to using sql in your templates, albeit a little more
> elegantly.
>
> But this is really off topic, because I doubt the site is running slow
> because of the model loading. It is most likely an issue with server
> load and/or max clients on apache.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to