actionView not working for strings

I have a UserController in which i have the below actionView and LoadModel methods.

I have a user table which has username as the primarykey.

The actionView method is working fine only if the username is a number. If the username is a string like ‘abc’

the i am getting the message The system is unable to find the requested action "abc".

However i am able to access the model using the below URL

localhost/app/index.php/user/view/id/abc

but not with

localhost/app/index.php/user/abc

Can anyone help me with this


        public function actionView($id)

	{	

		Yii::trace('youoop','trace');		

		$this->render('view',array('model'=>$this->loadModel($id),));

		


	}


	public function loadModel($id)

	{

			

		$model=User::model()->findByPk($id);

		if($model===null)

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

		return $model;

	}

You should review your urlManager’s rules.

They might be something like this, if you are using the default rules provided by Yii.




'urlManager'=>array(

	'urlFormat'=>'path',

	'rules'=>array(

		'<controller:\w+>/<id:\d+>'=>'<controller>/view',

		'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

		'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

	),

),



"<id:\d+>" says that "id" should be numerical. So when you provide a non-numerical "id", it will not be treated correctly by this set of rules.

But you will not be able to solve the problem by simply changing “<id:\d+>” to “<id:\w+>”. If you would do so, then all the urls with the pattern of “<\w+>/<\w+>” will be routed to “<controller>/view”. … I don’t have a quick solution right now.

Anyway, you would want to check the guide. URL Management

And welcome to the forum! Have fun! :)

Esta es la solucion a este problema:

en el config/main.php cambia algunos parametros, algunos d+ por w+ y unos w+ por unos d+. y que quede de esta manera a mi me funciono. debe quedar asi.

	'urlManager'=&gt;array(


		'urlFormat'=&gt;'path',


		'showScriptName'=&gt;false,


        'urlSuffix'=&gt;'/',


		'rules'=&gt;array(


			'&lt;controller:&#092;d+&gt;/&lt;id:&#092;w+&gt;'=&gt;'&lt;controller&gt;/view',


			'&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;/&lt;id:&#092;w+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;',


			'&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;',





		),


	),

apologizes for not writing

Hi phani,

You can do the following in the URLmanager,




'urlFormat'=>'path',

        'rules'=>array(

                '<controller:mycontroller>/<id:\S+>'=>'mycontroller/view',

                '<controller:\w+>/<id:\d+>'=>'<controller>/view',

                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

        ),



where even if you have any characters in the id you will be redirected to view of mycontroller

Note: As Softark said if you directly change \d+ to \w+ , it would redirect in case of any controllers which is true and not a good idea. But here we are allowing this in case of only one controller named mycontroller.

So I hope we are safe. :)