Defaultaction Dont Act In Controller [Solved]

[]What factors causes


public $defaultAction = 'someAction';

don’t act?

[b]ProfileController:




<?php


class ProfileController extends Controller

{

	private $_model;

	public $defaultAction = 'Update';




	public function filters()

	{

    	return array(

        	'accessControl',

    	);

	}


	public function accessRules()

	{

    	return array(

        	array('allow',

            	'actions'=>array(),

            	'roles'=>array('user'),

        	),

        	array('deny'),

    	);

	}


	public function actionUpdate()

	{

    	$model = $this->loadModel();

    	$model->scenario = 'updateProfile';

    	$this->performAjaxValidation($model,'profile-form');


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

    	{

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

        	if($model->validate()){

            	$model->save();

            	//$this->redirect(array('index'));

        	}

    	}

    	$this->render('profile',array('model'=>$model));

	}


	public function actionEmail()

	{

    	$model = $this->loadModel();

    	$model->scenario = 'changeEmail';

    	$this->performAjaxValidation($model,'email-form');


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

    	{

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

        	if($model->validate()){


            	$oldEmail = new OldEmail();

            	$oldEmail->user_id = $model->id;

            	$oldEmail->username = $model->username;

            	$oldEmail->email = $model->email;


            	$verifyString = simple_random_string();

            	$model->verify_string = $verifyString;

            	$model->email = $model->newEmail;

            	$model->status = User::Inactive;


            	$transaction = Yii::app()->db->beginTransaction();

            	try{

                	$model->save();

                	$oldEmail->save();

                	$transaction->commit();

            	}catch (Exception $e){

                	$transaction->rollback();

                	throw new Exception(Yii::t('application','System not able process this progress.'));

            	}


            	$url = Yii::app()->createAbsoluteUrl('site/verify',array(

                	'type'=>'email','verifyString'=>$verifyString));

            	send_email_verify_code($url,$model->username,$model->email);

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

				Yii::app()->user->setFlash('emailChanged','true');

        	}

    	}

    	$this->render('email',array('model'=>$model));

	}


	public function actionPass()

	{

    	$model = $this->loadModel();

    	$model->scenario = 'changePass';

    	$this->performAjaxValidation($model,'password-form');


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

    	{

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

        	if($model->validate()){

            	$model->password = password_hash($model->newPass, PASSWORD_BCRYPT);

            	if($model->save())

                	$this->redirect(array('profile/'));

        	}

    	}

    	$this->render('password',array('model'=>$model));

	}


	public function actionIndex()

	{

    	$this->render('index');

	}


	public function loadModel()

	{

    	if(is_null($this->_model))

    	{

        	if(isset(Yii::app()->user->id))

            	$this->_model = User::model()->findByPk((int)Yii::app()->user->id);

        	if(is_null($this->_model))

            	throw new CHttpException(404,Yii::t('application','The requested page does not exist.'));

    	}

    	return $this->_model;

	}


	protected function performAjaxValidation($model,$form)

	{

    	if(isset($_POST['ajax']) && $_POST['ajax']==$form)

    	{

        	echo CActiveForm::validate($model);

        	Yii::app()->end();

    	}

	}

}



[/b]I want default action is "update", but "index" is default action !!!

DefaultAction only works when there’s no information about requested action.

It will not fire if you you have some routes pointing to specific action.

So make sure that

  1. you’re requesting URL without specifying the action (/profile in your case)

  2. there are no routing rules that bind your url to some specific action (like ‘<_c:\w+>’ => ‘<_c>/index’)

Or maybe use your action name in lower case in start character:




public $defaultAction = 'update';



Thanks friend

I had exactly the same two errors. Both.