Re: Loading many Model in a Cakephp controller
Thanks, got the point :-) On 11 apr, 13:08, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote: > > Question: When would one deside to use ClassRegistry::init instead of > > App:Import and new() ? Wouldn't that be more memory efficient? > > ClassRegistry::init() would store a reference, so it can be reused > later and use App::import() internally. Use it if you plan reuse the > instance in other place. > > ClassRegistry::init() calls internally to App::import() and new, in > case of an not loaded object, so there isn't any performance penalty > in using any. But on the other hand, if the object is already loaded, > ClassRegistry::init() would reuse the instance, so in that case it > will be more efficient. > > > > > On 11 apr, 01:59, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote: > > > > I was wondering if it is possible to load models inside a controller > > > > in the similar way as codeigniter does, and if there is a way, how to > > > > do it > > > > Yes, Well if you want to use more than one model in the same > > > controller, just tell cake so: > > > > class FoosController extends AppController { > > > > var $name = 'Foos'; > > > > var $uses = array('Model1', 'Model2', 'Model3'); > > > > function index() { > > > > $ones = $this->Model1->findAll(); > > > $twos = $this->Model2->findAll(); > > > > } > > > } > > > > If you prefer to load them yourself, set uses to array(); (or don't > > > define it and cake will only load the default model). Then : > > > > CakePHP 1.2: > > > > if (App::import('Model', 'TheModel')) { > > > $this->TheModel = new TheModel(); > > > > } > > > > CakePHP 1.1 > > > > if (loadModel('TheModel')) { > > > $this->TheModel = new TheModel(); > > > > } > > > > Also remember that you can access related models in cake: > > > > $this->User->Group->findAll() > > > > By the way, all of this is in the official documentation > > (http://book.cakephp.org), so next time save your time and go directly > > > there. > > > > > It would be something like this > > > > > class Blog_controller extends Controller { > > > > > function blog() > > > > { > > > > $this->load->model('users_model','um'); > > > > $this->load->model('pictures_model','pm'); > > > > > $this->pm->findAll(); > > > > > $data['users'] =$this->um->findAll(); > > > > $data['pictures'] = $this->pm->findAll(); > > > > $this->load->view('blog', $data); > > > > } > > > > } > > > > > Can I load more that a model in a cakephp controller, in the case I > > > > need to acces more than one model in a controller? > > > > > thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Loading many Model in a Cakephp controller
> Question: When would one deside to use ClassRegistry::init instead of > App:Import and new() ? Wouldn't that be more memory efficient? ClassRegistry::init() would store a reference, so it can be reused later and use App::import() internally. Use it if you plan reuse the instance in other place. ClassRegistry::init() calls internally to App::import() and new, in case of an not loaded object, so there isn't any performance penalty in using any. But on the other hand, if the object is already loaded, ClassRegistry::init() would reuse the instance, so in that case it will be more efficient. > > > On 11 apr, 01:59, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote: > > > I was wondering if it is possible to load models inside a controller > > > in the similar way as codeigniter does, and if there is a way, how to > > > do it > > > > Yes, Well if you want to use more than one model in the same > > controller, just tell cake so: > > > > class FoosController extends AppController { > > > > var $name = 'Foos'; > > > > var $uses = array('Model1', 'Model2', 'Model3'); > > > > function index() { > > > > $ones = $this->Model1->findAll(); > > $twos = $this->Model2->findAll(); > > > > } > > } > > > > If you prefer to load them yourself, set uses to array(); (or don't > > define it and cake will only load the default model). Then : > > > > CakePHP 1.2: > > > > if (App::import('Model', 'TheModel')) { > > $this->TheModel = new TheModel(); > > > > } > > > > CakePHP 1.1 > > > > if (loadModel('TheModel')) { > > $this->TheModel = new TheModel(); > > > > } > > > > Also remember that you can access related models in cake: > > > > $this->User->Group->findAll() > > > > By the way, all of this is in the official documentation > (http://book.cakephp.org), so next time save your time and go directly > > there. > > > > > It would be something like this > > > > > class Blog_controller extends Controller { > > > > > function blog() > > > { > > > $this->load->model('users_model','um'); > > > $this->load->model('pictures_model','pm'); > > > > > $this->pm->findAll(); > > > > > $data['users'] =$this->um->findAll(); > > > $data['pictures'] = $this->pm->findAll(); > > > $this->load->view('blog', $data); > > > } > > > } > > > > > Can I load more that a model in a cakephp controller, in the case I > > > need to acces more than one model in a controller? > > > > > thanks > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Loading many Model in a Cakephp controller
Question: When would one deside to use ClassRegistry::init instead of App:Import and new() ? Wouldn't that be more memory efficient? On 11 apr, 01:59, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote: > > I was wondering if it is possible to load models inside a controller > > in the similar way as codeigniter does, and if there is a way, how to > > do it > > Yes, Well if you want to use more than one model in the same > controller, just tell cake so: > > class FoosController extends AppController { > > var $name = 'Foos'; > > var $uses = array('Model1', 'Model2', 'Model3'); > > function index() { > > $ones = $this->Model1->findAll(); > $twos = $this->Model2->findAll(); > > } > } > > If you prefer to load them yourself, set uses to array(); (or don't > define it and cake will only load the default model). Then : > > CakePHP 1.2: > > if (App::import('Model', 'TheModel')) { > $this->TheModel = new TheModel(); > > } > > CakePHP 1.1 > > if (loadModel('TheModel')) { > $this->TheModel = new TheModel(); > > } > > Also remember that you can access related models in cake: > > $this->User->Group->findAll() > > By the way, all of this is in the official documentation > (http://book.cakephp.org), so next time save your time and go directly > there. > > > It would be something like this > > > class Blog_controller extends Controller { > > > function blog() > > { > > $this->load->model('users_model','um'); > > $this->load->model('pictures_model','pm'); > > > $this->pm->findAll(); > > > $data['users'] =$this->um->findAll(); > > $data['pictures'] = $this->pm->findAll(); > > $this->load->view('blog', $data); > > } > > } > > > Can I load more that a model in a cakephp controller, in the case I > > need to acces more than one model in a controller? > > > thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Loading many Model in a Cakephp controller
> I was wondering if it is possible to load models inside a controller > in the similar way as codeigniter does, and if there is a way, how to > do it Yes, Well if you want to use more than one model in the same controller, just tell cake so: class FoosController extends AppController { var $name = 'Foos'; var $uses = array('Model1', 'Model2', 'Model3'); function index() { $ones = $this->Model1->findAll(); $twos = $this->Model2->findAll(); } } If you prefer to load them yourself, set uses to array(); (or don't define it and cake will only load the default model). Then : CakePHP 1.2: if (App::import('Model', 'TheModel')) { $this->TheModel = new TheModel(); } CakePHP 1.1 if (loadModel('TheModel')) { $this->TheModel = new TheModel(); } Also remember that you can access related models in cake: $this->User->Group->findAll() By the way, all of this is in the official documentation ( http://book.cakephp.org ), so next time save your time and go directly there. > It would be something like this > > class Blog_controller extends Controller { > > function blog() > { > $this->load->model('users_model','um'); > $this->load->model('pictures_model','pm'); > > > $this->pm->findAll(); > > $data['users'] =$this->um->findAll(); > $data['pictures'] = $this->pm->findAll(); > $this->load->view('blog', $data); > } > } > > Can I load more that a model in a cakephp controller, in the case I > need to acces more than one model in a controller? > > thanks > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Loading many Model in a Cakephp controller
I was wondering if it is possible to load models inside a controller in the similar way as codeigniter does, and if there is a way, how to do it It would be something like this class Blog_controller extends Controller { function blog() { $this->load->model('users_model','um'); $this->load->model('pictures_model','pm'); $this->pm->findAll(); $data['users'] =$this->um->findAll(); $data['pictures'] = $this->pm->findAll(); $this->load->view('blog', $data); } } Can I load more that a model in a cakephp controller, in the case I need to acces more than one model in a controller? thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---