Yii Framework Forum: Problem with Primary Key (VarChar) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problem with Primary Key (VarChar) Rate Topic: ***** 1 Votes

#1 User is offline   -=YiieRz=- 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 27-October 10
  • Location:Jakarta

Posted 05 January 2011 - 02:27 AM

I have problem if the primary key is varchar,

the problem is urlManager cannot find the true path
eg : http://xxxxx/site/in...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',
			),
		),

belajar itu modal utama, tanpa percobaan itu tak akan berhasil. berdoa itu membuat kita percaya diri. YiieRz-SdgBlajar
www.yiiframework.com
0

#2 User is offline   -=YiieRz=- 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 27-October 10
  • Location:Jakarta

Posted 05 January 2011 - 03:07 AM

Help
belajar itu modal utama, tanpa percobaan itu tak akan berhasil. berdoa itu membuat kita percaya diri. YiieRz-SdgBlajar
www.yiiframework.com
0

#3 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 05 January 2011 - 04:29 AM

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.
0

#4 User is offline   -=YiieRz=- 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 27-October 10
  • Location:Jakarta

Posted 05 January 2011 - 08:29 AM

View Postandy_s, on 05 January 2011 - 04:29 AM, said:

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)


2. 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;
}

belajar itu modal utama, tanpa percobaan itu tak akan berhasil. berdoa itu membuat kita percaya diri. YiieRz-SdgBlajar
www.yiiframework.com
0

#5 User is offline   jrewing 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 09-December 10

Posted 27 April 2011 - 08:34 AM

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

#6 User is offline   freshyiiuser 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 07-March 13

Posted 31 October 2013 - 04:05 PM

this solution is not working with me
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users