开发者

Pass back an id for a new record in another model to the controller

I am creating a small and simple warehouse application (for assets). I want to log all operati开发者_开发技巧ons so I made an afterSave method in Asset model.

This method imports the Log model and create an entry in it based on the datas have been sent. Works quite fine :)

For visual feedback to the user I would like to display the ID of the new log entry, so I need to send it back to the controller. I googled around a lot but did not find anything to help me how to start it at all.

How to pass back this new ID?


You could save the id in the model itself and retrieve it from there.

Model:

var $logId = 0;

function afterSave( $created ) {
    // data saving code

    $this->logId = $this->Log->getInsertId();
}

Controller:

$this->Asset->save( $this->data );
$this->set( 'logId', $this->Asset->logId );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜