Yii Framework Forum: Get Id In Url And Save It In A Variable - Yii Framework Forum

Jump to content

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

Get Id In Url And Save It In A Variable Rate Topic: -----

#1 User is offline   jr_jags 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 05-November 12
  • Location:Philippines

Posted 21 January 2013 - 10:33 AM

i have a button on my Cgrid that serves as an update button, when i click it, It sends me to my with the following url:

http://localhost/Add...unt/update&id=1

Is there a way I can get the number of the id in my URL, so that I can use it in my update form?

Or is there another approach for updating a record using CFormModel

here is my button on CGrid:

array(
'class'=>'CButtonColumn',
'template'=>'{update}',
'header'=>'Action',
'buttons'=>array(
'update'=>array(
'url'=>'Yii::app()->createUrl(\'account/update\', array(\'id\'=>$data[\'AID\']))',
),
),
),
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 21 January 2013 - 12:02 PM

Just use $id, provided that the model function has id as a parameter.

Yii does some magic behind the scenes.
"Less noise - more signal"
0

#3 User is offline   outrage 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 312
  • Joined: 10-November 09
  • Location:Blackpool, United Kingdom

Posted 21 January 2013 - 04:22 PM

Your existing url would work if your action looks like this:

public function actionUpdate($id) {
    ...
}


You could also use this:

$id = Yii::app()->request->getQuery('id');


Or plain PHP:

$id = $_GET['id'];

2

#4 User is offline   jr_jags 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 05-November 12
  • Location:Philippines

Posted 21 January 2013 - 05:33 PM

oh wow, it works, Thank You very much
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