What is the difference between redirection and rendering in CakePHP?

Is there any other command to redirect the controller to a specific view page other than redirection and rendering?

I have a redirect like

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

But if I give

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

it is not redirected to this page.

Something is wrong?

+6
redirect cakephp
source share
1 answer

A redirect call () throws an HTTP redirect . Nothing happens after the redirect because CakePHP just stops. Everything that you put after the redirection call will not be executed. Instead, the browser simply issues a new HTTP GET URL to which you redirect.

The call to render () just loads the view. It takes a path to the view, not the URL. It is not redirected. Suppose $ userID is "101" in your case. The render () call will attempt to load the following file:

application / views / Formwork / Home / 101.ctp

Since this file does not exist, nothing happens.

+12
source share

All Articles