Redirect Not Working

Logout not redirecting in the way as expected. I use the following to redirect

$this->redirect(Yii::app()->baseUrl); the error i get is "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

I mostly think this is due to the headers already sent issue. I user ob_start and ob_flush… But doesnt help. Any ideas?

This is my controller code

ob_start();

ob_flush();

Yii::app()->user->logout();

unset(Yii::app()->session[‘uid’]);

$this->redirect(Yii::app()->baseUrl);

Try this

Yii::app()->request->baseUrl

No that did not work either

In my controller Yii::app()->homeUrl echoes index.php, where as Yii::app()->baseUrl value is empty. But in my view the baseUrl echoes the value i.e url

then try something like this

else $this->redirect(Yii::app()->createUrl(‘controller/action’));

change controller and action as per your requirement.

What you are getting in


Yii::app()->baseUrl

Your error shows that where you redirecting goes to infinite loop.

Please show your controller action / method where you redirecting.

That would work , the problem is i have written .htaccess for removing index.php from the site, but when logging out, it prompts me with mywebsite.com.index.php… so do we have any urlManagement to redirect if the url comes as mywebsite.com/index.php

In your sitecontroller method


    public function actionLogout()

    {

        Yii::app()->user->logout();

        $this->redirect(Yii::app()->homeUrl);

//        $this->redirect(Yii::app()->baseUrl); //Or Try this

    }

on another note you have put this in your main.php under urlManager to remove index.php


'showScriptName' => false,

Yeah , thats right, thank you dude , i just forgot that part…