我正在从另一个控制器的方法中调用一个控制器方法。我可以确认正在调用该方法,因为当我对传递的数据执行 print_r 时,我看到了我期望的一切。我的问题是,当我调用 $this->Log->save($this->data) 时,没有任何东西写入数据库。我是一名 .NET 开发人员,因此我对 cakePHP 知之甚少,但我知道这是应该将内容保存到数据库的方式,因此我很困惑。
<?php
//The calling controller
App::import('Controller', 'Logs');
class othAuthComponent extends Object //I noticed this inherits from Object,
//but it doesn't seem to be a problem
{
function SomeFunction()
{
//create instance of our Logs controller as per example
$Logger = new LogsController;
$Logger->constructClasses();
$Logger->cms_addlog($user['User']['name'].' Logged in', $user['User']['id']);
}
}
?>
和罪犯:
<?php
//the called controller
class LogsController extends AppController
{
function cms_addlog($note,$ba_id)
{
$this->Log->create();
$curDateTime = getdate();
$this->data['LogTime'] = $curDateTime;
$this->data['Note'] = $note;
$this->data['brandactivatorid'] = $ba_id;
//print_r($this->data);
//die();
$this->Log->save($this->data);
}
}
?>