[英]Phalcon\Mvc\Model::beforeCreate() method
If i try to save model with date_created field defined in beforeCreate() method, it does not save it: 如果我尝试使用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';
}
}
Controller action context: 控制器动作上下文
$test = new TestEntity();
$test->name = 'test';
var_dump($contact->save()); // gives false
var_dump($contact->getMessages()); // says date_created is not defined
You need to assign the creation date before the null validation is performed: 您需要在执行空验证之前分配创建日期:
<?php
class TestEntity extends Phalcon\Mvc\Model
{
public function beforeValidationOnCreate()
{
$this->date_created = date('Y-m-d H:i:s');
}
/**
* Returns source table name
* @return string
*/
public function getSource()
{
return 'test_entity';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.