KItis
KItis

Reputation: 5646

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

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.

Upvotes: 7

Views: 9645

Answers (3)

mario
mario

Reputation: 145482

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.

Upvotes: 12

Deniyal Tandel
Deniyal Tandel

Reputation: 632

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

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

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

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

Upvotes: 0

dRocking
dRocking

Reputation: 41

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.

Upvotes: 0

Related Questions