我正在编写的模块(商店产品模块)有问题。
当我运行一次表单验证时,一切都很好。但是,当我edit()
再次运行产品并运行验证时(这是我所期望的),但它返回一个错误,指出 slug 必须是唯一的。
如何更改编辑模式的验证规则以忽略检查现有行/字段?
下面是我的控制器类的一个子集:
public function create() {
//this works fine
$this->form_validation->set_rules('slug', 'Slug',
'trim|required|is_unique[shop_products.slug]');
if ($this->form_validation->run()) { }
}
//when this runs the validation for slug returns saying not unique
// do i need a different validation rule ??
public function edit($id = 0) {
$this->data = $this->products_m->get($id);
$this->form_validation->set_rules('slug', 'Slug',
'trim|required|is_unique[shop_products.slug]');
if ($this->form_validation->run()) { }
}