无法从不同的模型调用插件模型函数

时间:2013-04-30 14:22:09

标签: cakephp cakephp-2.2

我有一个模型,需要通过特定的插件并调用其模型中的函数。我可以调用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;
}

我做错了什么?

0 个答案:

没有答案