> Yeah. I tried taking the function in the model. And then, I added User in
> the $uses array of photos controller and it worked.

>From the book:

"It's bad practice to just add all the models your controller uses to the
$uses array. Check here and here to see how to properly access associated
and unassociated models respectively."

http://book.cakephp.org/view/961/components-helpers-and-uses

mikek

>
> Rishab
> Sent from BlackBerryŽ on Airtel
>
> -----Original Message-----
> From: Jeremy Burns | Class Outfit <jeremybu...@classoutfit.com>
> Sender: cake-php@googlegroups.com
> Date: Mon, 11 Apr 2011 15:15:51
> To: <cake-php@googlegroups.com>
> Reply-To: cake-php@googlegroups.com
> 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
>
> jeremybu...@classoutfit.com
> 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
>> cake-php+unsubscr...@googlegroups.com 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
> cake-php+unsubscr...@googlegroups.com 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
> cake-php+unsubscr...@googlegroups.com 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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to