>  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 [email protected]
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