GetYii 搜索是基于 xunsearch 开发的,考虑到安装门槛,所以默认关闭此功能,需要开启的话,先安装 xunsearch,再修改配置文件就可以了。
详情看这篇文章:https://getyii.com/topic/61
model 内函数验证,参考代码:
use yii\base\Model;
class MyForm extends Model
{
public $country;
public $token;
public function rules()
{
return [
// an inline validator defined as the model method validateCountry()
['country', 'validateCountry'],
// an inline validator defined as an anonymous function
['token', function ($attribute, $params, $validator) {
if (!ctype_alnum($this->$attribute)) {
$this->addError($attribute, 'The token must contain letters or digits.');
}
}],
];
}
public function validateCountry($attribute, $params, $validator)
{
if (!in_array($this->$attribute, ['USA', 'Indonesia'])) {
$this->addError($attribute, 'The country must be either "USA" or "Indonesia".');
}
}
}
来源:https://www.yiiframework.com/doc/guide/2.0/en/input-validation#creating-validators
@gaoyl101 哦,是我的问题,看出差别了,建议你安装的时候用 composer install
命令试试看,不行的话你再试试 composer update
@gaoyl101 https://www.weixin-php.cn/markdown 我看没问题啊?
创业不容易啊,支持。可以加我微信,交个朋友。我的微信号,就靠你自己找了。
public function beforeValidate()
{
if (parent::beforeValidate()) {
return true;
}
return false;
}