Comments: requestAction

By poppitypop on 24/6/08

1 - Well written article

One question though: Will requestAction work if the action is prefixed with an underscore (eg _getUserList)? Because one would usually want to do this often me thinks!

(for those that don't remember actions prefixed with an underscore are not accessible to the public directly. Eg. /controller/_action would not work)

By Bo_oz on 26/6/08

2 - How does this work?

How do you access the data when you use the requestAction inside the renderElement:

<?php

echo $this->renderElement(

'users',

$this->requestAction('/users/getUserList') // <--- How do you use this!!

);

?>

By mustan9 on 10/7/08

3 - This documentation appears incorrect.

In the example of calling an element it should define the variable name.

echo $this->element('users',array('users'=>$this->requestAction('/users/getUserList')));

or, the getUserList method should return an array

return array('users'=>$this->User->findAll('User.active = 1'));

You can now use the data in the variable $user within your element.

By Snadly on 10/7/08

4 - A note on requestAction

In 1.2 it is better practice to call requestAction() with array style parameters. I ran in to an issue with a trailing backslash that can be avoided by using the array style of passing. This method is also better for performance.

Here is an example.

$this->requestAction( array( 'controller' => 'controllerName', 'action' => 'requestedAction' ), array( 'pass' => array( 5, 'Test' ) ) );

Note: 'pass' is the arguments to the action being called. They show up in the order listed in the array.

By BrendonKoz on 14/7/08

5 - When used in conjunction with ACL/Auth

Be aware that if a controller action has certain restrictions on it within Auth and/or ACL that when calling it via requestAction will maintain those restrictions. Although common sense would deem this easy to diagnose, one can easily forget about restrictions when simply trying to get something to work.

By alfonso.nishikawa on 27/10/08

6 - Evaluating this article

After revision 5018 I dont find it thin and clear enough :S

Could anyone complete and improve it?