developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #618: jcontrollerdaocrud.diff

File jcontrollerdaocrud.diff, 2.4 KB (added by bastnic, 12 years ago)
  • lib/jelix/controllers/jControllerDaoCrud.class.php

     
    253253    protected function _create($form, $resp, $tpl) {
    254254
    255255    }
     256   
     257    /**
     258     * overload this method if you wan to do additionnal things on the dao generated by the
     259     * jFormsBase::prepareDaoFromControls method
     260     * @param jFormsBase $form the form
     261     * @param jDaoRecordBase $form_daorec
     262     */   
     263    protected function _beforeSaveCreate($form, $form_daorec) {
    256264
     265    }
     266   
    257267    /**
    258268     * save data of a form in a new record
    259269     */
     
    266276        }
    267277
    268278        if($form->check() && $this->_checkData($form, false)){
    269             $id = $form->saveToDao($this->dao, null, $this->dbProfil);
     279            extract($form->prepareDaoFromControls($this->dao,null,$this->dbProfil),
     280                                                                EXTR_PREFIX_ALL, "form");
     281                        $this->_beforeCreate($form, $form_daorec);
     282                $form_dao->insert($form_daorec);
     283                $id = $form_daorec->getPk();
    270284            $form->saveAllFiles($this->uploadsDirectory);
    271285            $rep->action = $this->_getAction('view');
    272286            $this->_afterCreate($form, $id, $rep);
     
    353367    protected function _editUpdate($form, $resp, $tpl) {
    354368
    355369    }
     370   
     371    /**
     372     * overload this method if you wan to do additionnal things on the dao generated by the
     373     * jFormsBase::prepareDaoFromControls method
     374     * @param jFormsBase $form the form
     375     * @param jDaoRecordBase $form_daorec
     376     * @param mixed $id the new id of the updated record
     377     */   
     378    protected function _beforeSaveUpdate($form, $form_daorec, $id) {
    356379
     380    }
     381
    357382    /**
    358383     * save data of a form in a new record
    359384     */
     
    367392        }
    368393
    369394        if($form->check() && $this->_checkData($form, true)){
    370             $id = $form->saveToDao($this->dao, null, $this->dbProfil);
     395            extract($form->prepareDaoFromControls($this->dao,$id,$this->dbProfil),
     396                                                                EXTR_PREFIX_ALL, "form");
     397                        $this->_beforeUpdate($form, $form_daorec, $id);
     398            $form_dao->update($form_daorec);
    371399            $form->saveAllFiles($this->uploadsDirectory);
    372400            $rep->action = $this->_getAction('view');
    373401            $this->_afterUpdate($form, $id, $rep);