October/Winter CMS表单预设值的处理

OctoberCMS中的slug字段类型在preset设置title的时候对中文无效,如果懒得手动输入可以在Model中使用beforeValidate方法来处理,这样还避免了rules的冲突

    public function beforeValidate(){
        if(!$this->slug){
            $slugString = $this->title;
            if(!preg_match("/[a-z]/i", $slugString)){
                $slugString = urlencode($slugString);   //中文转码
            }
            $this->slug = str_slug($slugString);
        }
    }

Post Comment