【发布时间】:2013-02-01 14:58:29
【问题描述】:
如果我尝试使用 beforeCreate() 方法中定义的 date_created 字段保存模型,它不会保存它:
class TestEntity extends Phalcon\Mvc\Model
{
public function beforeCreate()
{
$this->date_created = date('Y-m-d H:i:s');
}
/**
* Returns source table name
* @return string
*/
public function getSource()
{
return 'test_entity';
}
}
控制器动作上下文:
$test = new TestEntity();
$test->name = 'test';
var_dump($contact->save()); // gives false
var_dump($contact->getMessages()); // says date_created is not defined
【问题讨论】:
-
test_entity表中的字段是否名为 date_created? -
@NikolaosDimopoulos 正如 twistedxtra 所说,有必要使用一点不同的方法 beforeValidationOnCreate()。谢谢你:)