当我添加所需规则时,验证通过即使在post数据中不包含(name),但如果我有其他规则,如(valid_email),验证返回false。
我的模型:
namespace AppModels;
use CodeIgniterModel;
class ProjectsMD extends Model
{
protected $table = 'projects';
protected $primaryKey = 'sid';
protected $returnType = 'AppEntitiesProject';
protected $allowedFields = ['name', 'description', 'location', 'area', 'client', 'stage'];
protected $validationRules = [
'name' => ['label' => 'App.name', 'rules' => 'required'],
];
protected $useTimestamps = true;
}
我的控制器:
public function projectsCreate()
{
$projectsMD = new AppModelsProjectsMD();
if($projectsMD->validate($this->request->getPost()) === false)
{
return false;
}
return true;
}
您是否检查了请求正文$this->request->getPost()
以确认name
值是否为而不是空数组、空字符串、null或false?
可用规则
规则 | 参数 | 描述 |
---|---|---|
required | No | 当字段为空数组、空字符串、null或false时失败 |