Re: ClassRegistry::init vs loadModel

2009-02-10 Thread gmwebs

Gwoo, I apologise if I have missed any posts on this in the past,
but...

I thought that loadModel() was deprecated? I remember going through
all my code and changing it to App::import based on the warning
message loadModel is deprecated see App::import
('Model', 'ModelName');?

Has this (or the preferred method) changed?

Again, sorry if I am just being dumb!
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: ClassRegistry::init vs loadModel

2009-02-10 Thread Gwoo

Yes the old loadModel() function from basics was deprecated.
However the loadModel() method in Controller is still used.
http://api.cakephp.org/class/controller#method-ControllerloadModel
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: ClassRegistry::init vs loadModel

2009-02-10 Thread Miles J

I wrote a post about this a few days ago.

http://www.milesj.me/blog/read/16/loading-models-specific-to-certain-actions
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



ClassRegistry::init vs loadModel

2009-02-09 Thread Henrik Gemal

I'm not sure what the most correct way to dynamicly load a model is:

ClassRegistry::init(model_name)
or
loadModel(model_name)

?
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: ClassRegistry::init vs loadModel

2009-02-09 Thread mscdex

On Feb 9, 7:57 am, Henrik Gemal henrikge...@gmail.com wrote:
 I'm not sure what the most correct way to dynamicly load a model is:

 ClassRegistry::init(model_name)
 or
 loadModel(model_name)

 ?

I use App::Import if I'm going to use a model instance more than once.
Otherwise ClassRegistry::init can be used for one-time usage (e.g.
ClassRegistry::init(Foo)-find(all);).

However,  you should make sure you are not loading a model in which
the current model (of your controller) has an association with. If it
does, then you can just do $this-Bar-Foo-find(all); instead if
Bar is the current model.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: ClassRegistry::init vs loadModel

2009-02-09 Thread Gwoo

Ok hopefully this will be the last time we need to explain this...


App::import() only includes the file. So you would new to create a new
instance every time. This is not recommended

ClassRegistry::init() loads the file, adds the instance to the a
object map and returns the instance. This is an easy and convenient
way to access models.

Controller::loadModel(); Uses ClassRegistry::init() adds the model to
a property of the controller and also allows persistModel to be
enabled.

While you can do any of these things, you should ask yourself why
you are creating dependencies on models that are not natural to the
controller. If you have to do use any of these, then I would do so
in reverse order of the way i described them. IE, Controller::loadModel
() then CR::init() and actually I never use App::import() for models.

Hope this helps.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---