Redirect to Login after create

I am creating a survey for any guest to complete. You do not need to be logged in to create the survey, but Admins can manage it.

Everything works fine, but once the survey is sumbit it does not redirect to my Thank You page but rather to the Login Page. What am I missing?

My controller have theses accessRules


	public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('create'),

				'users'=>array('*'),

			),

			array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','update'),

				'users'=>array('@'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete','index','view'),

				'users'=>array('admin'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}

My create action looks like this


	public function actionCreate()

	{

		$model=new Survey;


		// Uncomment the following line if AJAX validation is needed

		$this->performAjaxValidation($model);


		if(isset($_POST['Survey']))

		{

			$model->attributes=$_POST['Survey'];

			if($model->save())

				$this->redirect('/site/page', 'view'=>'surveycomplete'); 

		}


		$this->render('create',array(

			'model'=>$model,

		));

	}

I tried diff. variations of the redirect. Even the site index does the same.

$this->redirect(’/site/index’);

Thanks


$this->redirect('/site/page', 'view'=>'surveycomplete'); 

The above is invalid,

needs to be


$this->redirect('/site/page', array('view'=>'surveycomplete')); 

Thanks, but it still directs me to the login screen and not the surveycomplete page.

Give permission to logged user for access this page:





        public function accessRules()

        {

                return array(

                        array('allow',  // allow all users to perform 'index' and 'view' actions

                                'actions'=>array('create'),

                                'users'=>array('*'),

                        ),

                        array('allow', // allow authenticated user to perform 'create' and 'update' actions

                                'actions'=>array('create','update', 'surveycomplete'),

                                'users'=>array('@'),

                        ),

                        array('allow', // allow admin user to perform 'admin' and 'delete' actions

                                'actions'=>array('admin','delete','index','view'),

                                'users'=>array('admin'),

                        ),

                        array('deny',  // deny all users

                                'users'=>array('*'),

                        ),

                );

        }



I added permission to logged in and all users to that page, but it still direct me to the login page.

The surveycomplete page itself is accessible similar to the about page that yii creates (http://localhost/site/page/view/surveycomplete and also http://localhost/site/page?view=surveycomplete).

I can access it normally without being logged in, but not through the redirect after a submit <_<

In your rules you’re giving access to “create” to everybody, but only authenticated users have access to “surveycomplete”. Try moving it to the 1st rule.

This is very strange.

The redirect to login is done if you have not permission to some page or if you call Yii::app()->user->logniRequired.

Be sure that:

You are redirecting to the correct page

You have the permission for access this page.

I think that there are no other options.

I noticed only now that you use the action page, not the action ‘surveycomplete’:


$this->redirect('/site/page', 'view'=>'surveycomplete'); 

Give the permission for the action page:




 public function accessRules()

        {

                return array(

                        array('allow',  // allow all users to perform 'index' and 'view' actions

                                'actions'=>array('create'),

                                'users'=>array('*'),

                        ),

                        array('allow', // allow authenticated user to perform 'create' and 'update' actions

                                'actions'=>array('create','update', 'page'),

                                'users'=>array('@'),

                        ),

                        array('allow', // allow admin user to perform 'admin' and 'delete' actions

                                'actions'=>array('admin','delete','index','view'),

                                'users'=>array('admin'),

                        ),

                        array('deny',  // deny all users

                                'users'=>array('*'),

                        ),

                );

        }



I changed the rules as you suggested, but still get the same result.

Pages are part of the site controller which is created by default, so it should be accessable even with no rules for it in other controllers. Like I said, I can open that page directly in my browser, but not through the redirect for some reason <_< .