PHP Freelancer

CakePHP : Load Other Model In Controller

05.08.2010 · Posted in CakePHP

Hello Friends, These days I am totally giving tricks and ideas relates to cakePHP and in this article I will also tell you how to load other model in other controller to use instantly. There are two ways to make available other model in controller, One is $uses variable in controller and other is loadModel function. $uses way is not efficient to make available or to include other model in controller So there is second way by which we can load other model in controller is loadModel function.

I am always using loadModel function to load model in controller but I am giving overview of both ways.

First I am explaining $uses variable method. Whenever you want to include or make available other model in controller than you can use $uses variable at start of controller like this
<?php
class RecipesController extends AppController {
var $name = 'Recipes';
var $uses = array('Product', 'User');
}
?>

As you see in above code by $uses variable I have included or make available two models Product and User, So If you want to make available other model in controller you can use $uses variable and than write your model name in that array.

Second way loadModel function, It is efficient way to make available model or load model in controller. Syntax of loadModel function :
$this->loadModel('User');
$users= $this->User->find('all');

In this way you can load model, Just pass model name in loadModel function and than you can use that model for Db interaction.

  • July 4th decorations
    If I get a serial to Ethernet and or wireless device for my micro controller would I be able to use PHP to retrieve the data that the controller is transmitting?
  • Actually i m learning cakePHP .. and i want to deploy my small applications so that i can show it to my friends.
blog comments powered by Disqus
Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Thank you for using IGIT Tweet Share Button, a plugin by HackingEthics