【发布时间】:2015-11-17 15:18:03
【问题描述】:
我编写了testAdd() 方法并尝试调试当前返回null 而debug($articles) 正确显示新插入的数据的$this->Article->getInsertID();。
public function testAdd() {
$data = array(
'Article' => array(
'title' => 'Fourth Title',
'content' => 'Fourth Title Body',
'published' => '1',
'created' => '2015-05-18 10:40:34',
'updated' => '2015-05019 10:23:34'
)
);
$this->_testAction('/articles/add', array('method' => 'post', 'data' => $data));
$articles = $this->Article->find('first', array('order' => array('id DESC')));
debug($articles);
debug($this->Article->getInsertID);
// return null.
}
为什么$this->Article->getInsertID() 返回null?
【问题讨论】:
-
您在示例代码中写了
$this->Article->getInsertID,不应该读为$this->Article->getInsertID()吗? -
我写了
$this->assertEqual(4, $this->Article->getInsertID),它显示了“断言 4 匹配预期空值失败”错误。 -
这是一个方法而不是一个属性! book.cakephp.org/2.0/en/models/…
-
是的,它插入一行已发布的数据。