Home » Php » php – What is the difference between $this->render() and $this->redirect()

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

Posted by: admin July 12, 2020 Leave a comment


I am 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.

How to&Answers:

It looks like they do quite different things:

  • ->redirect($url, ...)
    redirect does a HTTP page redirect. Does not directly render a page.

  • ->render($view, ...)
    render outputs the named view. Does not terminate the current PHP request.


After the redirect, the browser will request another page that will have its own render() call. With a redirect, you will see the url change in your address bar and a different page. Unless of course you are redirecting to the page that you were already on.



this is better used when you want to render same page beacause it’s store action means it’s cant change browser url.


this is better to use for show different page because it’s change url as well as action.