Yii Framework Forum: Return Id Auto Increment - Yii Framework Forum

Jump to content

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

Return Id Auto Increment How return Object with Auto Increment Field ID? Rate Topic: -----

#1 User is offline   rith thy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 17-January 13

Posted 27 January 2013 - 03:20 AM

Hi Everyone,

I have a problem with Yii Framework.

public function doRestCreate($data)
{
$model = $this->getModel();
$ids = $this->saveModel($model, $data);
$this->renderJson($ids);

}

I can return this model(ID =0, Name = Test) my ID Field in database is auto increment, so I want to get create object include ID (get from ID field auto increment).

Please help me to create it.
0

#2 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 511
  • Joined: 08-August 09

Posted 28 January 2013 - 04:37 AM

Hi rith thy,


I didn't understand in details what's your exact problem according to the code provided. But in common, when you save the model, ID is available right after that as usual, $model->id. In addition, you may use getLastInsertID()

Hope this will help.
0

#3 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 08 February 2013 - 05:13 PM

/* moved to General Discussion */
(not a tip, snippet or tutorial)
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
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