Yii Framework Forum: Masalah Primary Key (Not Integer) - Yii Framework Forum

Jump to content

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

Masalah Primary Key (Not Integer) Rate Topic: -----

#1 User is offline   John_453P 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 24-March 11

Posted 04 January 2012 - 09:10 PM

Para masta sekalian..
Ini postingan mirip Cara Edit data Jika Primary Key berupa varchar postingan itu bisa mengatasi masalah tipe varchar yang datanya hanya angka (Jika huruf tidak bisa).

ane mau nanya, gmn caranya ya menampilkan data(view) jika primary key berupa huruf(bukan angka),

NIP(varchar)    | Nama
123             | Toni
123abc          | Dono 




=>controller
	public function loadModel($id)
	{       
		$model=Pegawai::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}


ane pakai cara itu hasilnya:
Jika saya view Toni(id=123) berhasil,
Jika ane view Dono(id=123abc)gagal gan, muncul pesan
The system is unable to find the requested action "123abc".


terus ane coba pake cara lain kayak gini, tapi hasilnya sama gan kaya di atas, ga da perubahan.
	public function loadModel($id)
	{      

               $model=Pegawai::model()->findByAttributes(array('NIP'=>$id));
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}

gimana solusinya ya? Mohon bantuannya gan? :(
0

#2 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 541
  • Joined: 21-June 10

Posted 05 January 2012 - 12:49 AM

Apakah agan mengaktifkan UrlManager di configurasi Yii?

Kalau ya mungkin bisa posting rule url managernya... Ane curiga bisa muncul error itu gara2 rule manager nya salah. Makanya errornya bilang "action xyz not found"
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#3 User is offline   John_453P 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 24-March 11

Posted 05 January 2012 - 01:57 AM

sebelumnya thanks udah di respon, ya gan ane ubah jadi kayak gini

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


tuh gmn ya?
0

#4 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 541
  • Joined: 21-June 10

Posted 05 January 2012 - 05:47 AM

coba ubah rule pertama yang ini:
'<controller:\w+>/<id:\d+>'=>'<controller>/view',

menjadi ini:
'<controller:\w+>/<id:\w+>'=>'<controller>/view',
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#5 User is offline   John_453P 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 24-March 11

Posted 07 January 2012 - 01:04 AM

Kalo view pake itu dah bisa gan, tapi pas ane coba create malah ga bisa, muncul gini
The requested page does not exist.

teruss..ane coba rule ke dua jadi kaya gini
'<controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>',

tapi tetep ga bisa, gmn ya gan ? :unsure:
0

#6 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 541
  • Joined: 21-June 10

Posted 07 January 2012 - 03:53 AM

View PostJohn_453P, on 07 January 2012 - 01:04 AM, said:

Kalo view pake itu dah bisa gan, tapi pas ane coba create malah ga bisa, muncul gini
The requested page does not exist.

teruss..ane coba rule ke dua jadi kaya gini
'<controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>',

tapi tetep ga bisa, gmn ya gan ? :unsure:


oh ya. ane gak memperkirakan rules lain... coba kita ganti rule sebelumnya biar muncul tulisan "view" di url saja.


'<controller:\w+>/view/<id:\w+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#7 User is offline   John_453P 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 24-March 11

Posted 07 January 2012 - 07:09 AM

View Postjunxiong, on 07 January 2012 - 03:53 AM, said:

oh ya. ane gak memperkirakan rules lain... coba kita ganti rule sebelumnya biar muncul tulisan "view" di url saja.


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



wah... mantap gan, akhirnya bisa. Kalo boleh tau kenapa bisa gitu ya, ane kurang paham konsepnya, mungkin ada link yg bisa ane baca terkait UrlManager.
Thanks 4 all junxiong.
The good jobs :D
0

#8 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 541
  • Joined: 21-June 10

Posted 07 January 2012 - 09:13 PM

View PostJohn_453P, on 07 January 2012 - 07:09 AM, said:

wah... mantap gan, akhirnya bisa. Kalo boleh tau kenapa bisa gitu ya, ane kurang paham konsepnya, mungkin ada link yg bisa ane baca terkait UrlManager.
Thanks 4 all junxiong.
The good jobs :D


Saya rasa Guide yang bisa menjadi tempat awal yang bagus untuk belajar:
http://www.yiiframew...1/en/topics.url

sekedar tambahan info, rules dibaca dari atas ke bawah, jadi kalau rules pertama terpenuhi maka Yii akan berhenti sampai situ. Itu sebabnya, urutan sangat penting.
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
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