Problem with Primary Key (VarChar)

I have problem if the primary key is varchar,

the problem is urlManager cannot find the true path

eg : http://xxxxx/site/index.php/item/update/ABC

or http://xxxxx/site/index.php/item/ABC

ABC is id (varchar)


'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>',

				'item/update/<id:\w+>'=>'item/update',

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

			),

		),

Help

Try to change the order of rules:




'item/update/<id:\w+>'=>'item/update',

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

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

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

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



More general rules (<controller>/<action>) must be in the end.

Thanks for your help.

finaly i can solve this problem,

  1. config/main.php

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

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

'<controller:\w+>/<action:(create|view|update|delete|admin|index)>'=>'<controller>/<action>', //limited for this action(create|view|update|delete|admin|index)

'<controller:(item)>/<action:\w+>/<id:\w+>'=>'item/<action>',

'<controller:(item)>/<id:\w+>'=>'item/view', //rules: do not insert primary key (create|view|update|delete|admin|index)

  1. controller/ItemController.php

public function loadModel($id)

{

	$model=Item::model()->findByPk((int)$id);

	if($model===null) {

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

		if($model===null)

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

	}

	return $model;

}

Had the same problem. Removing the typecasting to int seems to have resolved it.

this solution is not working with me

if is something about urlManager replacing <id:\d+> to <id:\w+> should work

<id:\d+> —> \d Matches a digit [0-9].

<controller:\w+> —> \w Matches an alphanumberic character.