📜  saveAll 获取所有id save cakephp 代码示例

📅  最后修改于: 2022-03-11 14:54:29.585000             🧑  作者: Mango

代码示例1
public $saved_ids = array(
        'insert' => array(
            'count' => 0, 'id' => array()
        ),
        'update' => array(
            'count' => 0, 'id' => array()
        )
    );


function afterSave( $created, $options = array() ){
        if( $created ){
            $this->saved_ids['insert']['count']++;
            $this->saved_ids['insert']['id'][] = $this->getID();    // get insert lasted id into database (vilh)
        } else {
            $this->saved_ids['update']['count']++;
            $this->saved_ids['update']['id'][] = $this->getID();
        }

        return $this->saved_ids;
    }


if ($this->MemberBookFacility->saveAll($data_MemberBookFacility)) {

    pr ($this->MemberBookFacility->saved_ids['insert']['id']);    // get multiple ids
}