P. 1
Super Awesome Advanced CakePHP Tips

Super Awesome Advanced CakePHP Tips

|Views: 2,846|Likes:
Published by isol123

More info:

Published by: isol123 on Jul 03, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

11/08/2012

pdf

text

original

Make sure you understand model chaining before reading this section. It is described
above in the “Don't Use uses Section” and a little bit in the Model section of the
Cookbook.

A lot of you probably realized that although it's great to be able to access related models through
chaining, building the chain on every request is not very efficient. Using persistent models
attempts to solve that problem by caching the objects, but this doesn't work in every application.
Particularly, if you access models using Controller::loadModel or ClassRegistry::init,
using persitent models will often give errors such as:

55

Catchable fatal error: Object of class __PHP_Incomplete_Class

Rather then caching the models, it makes sense to not create the chain by default and instead
add the links as needed. Thanks to PHP's __get() and __isset() this is possible. These
functions are part of PHP's overloading ability.
To accomplish this check out my LazyLoader plugin available from GitHub. Unfortunatly,
__isset() is only available in PHP 5.1.0 and above, so this code is limited to those versions.

Approximate Increase: Roughly 4-6% for every model that is unchained. You'll see the biggest
gain in applications with many interconnected models.

56

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->