I want to show the last login id from the database in view > _form.php file.I have made the code in _form.php file like this
<?php echo $form->labelEx($model,'id'); ?>
<?php echo Yii::app()->db->getLastInsertId('Form');?>
<?php echo $form->error($model,'id'); ?>
Here Form is the table and the model name.But Still I am getting ID:0.Where is the wrong part?
解决方案
Pekka's answer is good for common. But if you want to do that action in Yii Framework, try this:
$myModel = new $model;
$model -> savel(false);
echo $model->primaryKey; // Prints the last id.
Or you may try this too for general solution:
Yii::app()->db->getLastInsertID();
Finally, I suggest you to check out this