【发布时间】:2019-03-03 01:06:46
【问题描述】:
这是蛋糕 php 1.3
我在 appcontroller 中有一个名为 setLog() 的方法。我正在尝试将此方法用作所有控制器的通用方法。但是当在另一个控制器(委员会控制器)中调用它时,它会说
调用未定义的方法 CommitteesController::setLog()
我需要知道如何正确调用这个函数。
应用控制器
App::import('Controller', 'ActionLogs');
class AppController extends Controller {
public function setLog($action,$remark,$status){
$logs = new ActionLogsController;
$logs->constructClasses();
$data = ['action'=>$action,'user'=>$this->Auth->user('id'),'remark'=>$remark,'status'=>$status];
$logs->add($data);
}
}
委员会控制器
function add() {
if (!empty($this->data)) {
$this->Committee->create();
if ($this->Committee->save($this->data)) {
//create a log for success
$this->setLog('add new committee',json_encode($this->data),1);
$this->Session->setFlash(__('The committee has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The committee could not be saved. Please, try again.', true));
//create a log for failed
$this->setLog('add new committee',json_encode($this->data),0);
}
}
$committeeTypes = $this->Committee->CommitteeType->find('list');
$cond = array('group_id' => 2,'is_active' => '1');
$cond2 = array('group_id' => 4,'is_active' => '1');
$secretaryUserids = $this->Committee->SecretaryUserid->find('list', array('conditions' => $cond));
$assistantSecretaryUserids = $this->Committee->AssistantSecretaryUserid->find('list', array('conditions' => $cond2));
$this->set(compact('committeeTypes', 'secretaryUserids', 'assistantSecretaryUserids'));
}
【问题讨论】:
-
你应该会找到你的答案here
-
我已经完成了,在另一个控制器中调用方法。 cakephp 书说:“在 AppController 中创建的控制器属性和方法将可用于所有应用程序的控制器。它是创建所有控制器通用代码的理想场所。” .. 但我需要了解应用控制器
标签: php cakephp-1.3