Update: i wrote some wrong statements about the use of header in php; so forget that part :)
What i want is to fetch and display a controller's view (with controller's data) from another controller, without have url change in browser.
Some details:
I need this thing because i have a controller dispatcher that redirects internally to the other controllers.
I think the only (correct) solution is to use routes.php in /config with Router::connect and there use the logic that was in the dispatcher controller.
ummm... header() is the function to use for a redirect unless the PHP documentation is wrong. (http://php.net/manual/en/function.header.php) The core in cakePHP uses header for the redirect function (see lines 721 - 730 of cake/libs/controller.php).
So I am not certain what you mean "like normal PHP". CakePHP is PHP, it's just built on object oriented code. It's not magic or twisted ways of doing things. So to do a redirect in cake, you can simply use:
$this->redirect(array('controller' => 'my_controller', 'action' => 'my_action'));
And it will call the header() function.
Now. If you are dead set on not using redirect (maybe if you are going to an external site), you can call header() in the code. Just be sure you put the exit(); after the header call:
header('Location: http://call/my/url');
exit();
It will work just the same as redirect. It's just a lot of unnecessary extra work. Keep in mind that using redirect will maintain the domain name and build the URL for you automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With