1

我有一个模型需要通过特定的插件并在其模型中调用一个函数。我可以调用 find('all'),但不能调用模型内部的自定义函数。

模型调用插件的模型函数:

public function copy($id){
        $this->id = $id;
        $original = $this->read();
        $new = $original['DocModule'];
        unset($new['id']);
        if(!$this->save($new)){
            CakeLog::debug("Could not copy DocModule in DocModule.php");
            return false;
        }
        $newId = $this->getLastInsertID();

        $modelName = $original['Module']['name'];              

        $this->{$modelName} = ClassRegistry::init($modelName.'.'.$modelName);
        CakeLog::debug(print_r($this->{$modelName}->find('all'),1));
        $this->{$modelName}->copyModule($newId, $id);
    }

插件的模型功能:

public function copyModule($newDocModId, $oldDocModId) {        
    $old = $this->find('first', array('conditions' => array('doc_module_id' => $oldDocModId), 'recursive' => -1));
    $new = $old;
    unset($new['Weather']['id']);
    $new['Weather']['doc_module_id'] = $newDocModId;
    if (!$this->save($new)) {
        CakeLog::debug("Could not copy weather.  Old = " . $oldDocModId . " | New = " . $newDocModId);
        return false;
    }
    return true;
}

我究竟做错了什么?

4

0 回答 0