与
ESC
输入关键词搜索文章

phalcon model新增或更新自动检测required必填

全文约 96 字预计阅读 1 分钟
phalcon默认就会打开字段是否为空的检测,如下解决: 一、把数据库字段设置为可以为空。 二、给可以为空的字段设置默认值。
public function skipValidation($skipers=[])
    {
        foreach ($skipers as $skiper) {
            if (empty($this->$skiper)) {
                $this->$skiper = new \Phalcon\Db\RawValue('""');
            }
        }   
    }
public function beforeValidation()
{
     $this->skipValidation(['tag','source_url']);
}
三、关闭phalcon对字段是否为空的判断
public function initialize(){

    $this->setup(
        array('notNullValidations'=>false)
    );

  }
phalcon model新增或更新自动检测required必填
分享

发表评论

评论 0 条

暂无评论,来说点什么吧。