Answer the question
In order to leave comments, you need to log in
How to get the id of a newly added entry?
Hello. There is a model and an Order table. I write data to it:
$order = new Order();
$order->amount = Goods::model()->findByPk($goods_id)->price;
$order->order_date = Date('Y.m.d');
$order->save();
Answer the question
In order to leave comments, you need to log in
Has the record been added to the database? maybe a validation error or a sql error.
also see what $order->save() returns, true/false
$order->getPrimaryKey();
But, you may have an exception in this place if the record is not found. Better this way:
$goods = Goods::model()->findByPk($goods_id);
if ( $goods != null) {
$order = new Order();
$order->amount = ->$goods->price;
$order->order_date = Date('Y.m.d');
$order->save();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question