Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between redirect and render in CakePHP?

Is there any other command for redirecting a controller to a particular view page other than redirect and render?

I have the redirect as

$this->redirect('/forms/homepage/'.$userId);

But if I give

$this->render('/forms/homepage/'.$userId);

it doesn't get redirected to that page.

Is something wrong?

like image 410
Angeline Avatar asked Jul 02 '09 10:07

Angeline


1 Answers

The call to redirect() issues a HTTP redirect. Nothing happens after the redirect because CakePHP simply stops. Anything you put after the redirect call will not be executed. Instead, the browser simply issues a new HTTP GET to the URL you are redirecting to.

The call to render() simply loads a view. It takes a path to a view, not an URL. It does not redirect. Assume that $userID is '101' in your case. The call to render() would try to load the following file:

app/views/forms/homepage/101.ctp

Since that file does not exist, nothing happens.

like image 60
Sander Marechal Avatar answered Sep 18 '22 22:09

Sander Marechal