0
votes

I have a question. I'm trying to use the requestAction method of cakePHP to load a view file, but it doesn't seem to work. On their page we can read the following:

You can use requestAction() to retrieve a fully rendered view by passing 'return' in the options: requestAction($url, array('return'));

I tried doing that, but I still couldn't get the content of my .ctp view file. Is there anything that I'm missing?

By the way, I'm doing this inside of another view.

Thank you.

2
Can you paste your code that you are running? - Barry Chapman

2 Answers

1
votes

This function doesn't just load view files. It simulates a web browser accessing the URL and returns what ever the controller in question renders. The default behaviour is sending the result to output, if you use the return parameter you have to remember to print it yourself:

$this->requestAction("MyController/myaction/param");

is equivalent to

echo $this->requestAction("MyController/myaction/param", array("return"));
0
votes

requestAction calls an action, not the associated view. If you want to call the associated view you need to do it like this:

echo $this->requestAction("Mycontroller/myaction/param", array( 'return' ) );

That will let cake know to render the associated view file.