What is the difference between $ this-> render () and $ this-> redirect ()

I'm new to the Yii framework, and I would like to know the difference between $this->render() and $this->redirect() .
Both can be used to retrieve a given page.

+7
source share
3 answers

They seem to be doing very different things:

  • ->redirect($url, ...)
    redirect redirects an HTTP page. Does not display the page directly.

  • ->render($view, ...)
    render displays a named view. Does not complete the current PHP request.

+11
source

After redirecting, the browser will request another page, which will have its own call to render (). With redirects, you will see a change in the URL in the address bar and another page. Unless, of course, you are redirected to the page on which you were already.

0
source

-> Render ('$' view, ...)

this is best used when you want to display the same page, as this save action means that it cannot change the browser url.

-> redirect ('$ relative_url', ..)

this is best used to display another page because it changes the url as well as the action.

0
source

All Articles