How to use a function of a controller from another controller
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home