Try to link the models through associations ($hasMany etc) rather than just 
putting the table in the $uses array. It's more efficient.

Jeremy Burns
Class Outfit

[email protected]
http://www.classoutfit.com

On 11 Apr 2011, at 15:18, [email protected] wrote:

> Yeah. I tried taking the function in the model. And then, I added User in the 
> $uses array of photos controller and it worked.
> 
> Rishab 
> Sent from BlackBerry® on Airtel
> 
> -----Original Message-----
> From: Jeremy Burns | Class Outfit <[email protected]>
> Sender: [email protected]
> Date: Mon, 11 Apr 2011 15:15:51 
> To: <[email protected]>
> Reply-To: [email protected]
> Subject: Re: How to use a function of a controller from another controller
> 
> I would make those model functions (it looks like they are query type 
> functions anyway) and then - so long as the User model is related in some way 
> to the Photo model - you can access it like this: $users = 
> $this->Photo->User->getAllUsers();  If the Photo model is not directly 
> related to the User model (perhaps they are linked by a Photographer model) 
> then daisy chain the models: $users = 
> $this->Photo->Photographer->User->getAllusers();  You get the idea...
> 
> Jeremy Burns
> Class Outfit
> 
> [email protected]
> http://www.classoutfit.com
> 
> On 11 Apr 2011, at 15:10, Rishab Jain wrote:
> 
>> Hi all,
>> 
>> There's a controller:
>> 
>> class PhotosController extends AppController {
>>       var $name = 'Photos';
>> 
>>      function index()
>>      {
>>             // I need to call the method getAllUsers() of the Users
>> Controller here.
>>      }
>> }
>> 
>> ================================================
>> And, there's another controller.
>> 
>> class UsersController extends AppController {
>>       var $name = 'Users';
>> 
>>      function index()
>>      {
>> 
>>      }
>> 
>>      function getAllUsers($userid)
>>      {
>>               // get the array for all the users from the database
>> and return the same.
>>      }
>> }
>> 
>> ===============================================
>> 
>> Can anybody tell me how can this be done. I tried searching on the
>> internet, where people say that there are 2 ways of doing this.
>> 
>> ===============================================
>> 1.  App::import('Controller', 'Posts');
>> 
>> class CommentsController extends AppController {
>>   //Instantiation
>>   $Posts = new PostsController;
>>   //Load model, components...
>>   $Posts->constructClasses();
>> 
>>   function index($passArray = array(1,2,3)) {
>>     //Call a method from PostsController with parameter
>>     $Posts->doSomething($passArray);
>>   }
>> }
>> ===============================================
>> 2. Making it a model.
>> 
>> ===============================================
>> 
>> I get an error trying the first alternative. And I dont want to make
>> the function in the model. Let me know how can we do this.
>> 
>> regards,
>> Rishab
>> 
>> -- 
>> Our newest site for the community: CakePHP Video Tutorials 
>> http://tv.cakephp.org 
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
>> others with their CakePHP related questions.
>> 
>> 
>> To unsubscribe from this group, send email to
>> [email protected] For more options, visit this group at 
>> http://groups.google.com/group/cake-php
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at 
> http://groups.google.com/group/cake-php
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at 
> http://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to