11-15-2019, 06:40 AM
(This post was last modified: 11-15-2019, 01:54 PM by Hrodriguez18.
Edit Reason: Change Images for code
)
Hi guys. I have a problem when editing a row having a unique field, I have defined a "users" property in Config \ Validation, when I perform the validation of the controller side, it does not recognize the "ignore_value".
and does not validate for me, for the same id not work,
Thank you.
PHP Code:
//--------------------------------------------------------------------
// Rules Config\Validation
//--------------------------------------------------------------------
public $users = [
'email'=>[
'label'=>'email',
'rules'=>'required',
'errors'=>[]
],
'password'=>[
'label'=>'password',
'rules'=>'required',
'errors'=>[]
],
'username'=>[
'label'=>'username',
'rules'=>'required|is_unique[admin_users.username,id,$id]',
'errors'=>[]
],
];
PHP Code:
abstract class CoreController extends Controller implements Crud
{
protected $dataResponse = [];
protected $objForm = '';
protected $form;
protected $request;
protected $validationRules; // here define name for rule
PHP Code:
class Users extends CoreController
{
protected $dataResponse=['breadcum'=>'Users'];
protected $objForm = UserForm::class;
protected $model = UserModel::class;
protected $validationRules = 'users'; // set the name for users validation
public function __construct()
{
parent::__construct();
//Do your magic here
}
PHP Code:
public function new()
{
if($this->request->isAJAX() && $this->request->getMethod() === 'post')
{
echo $this->form($this->form);
}else
{
if($this->request->getMethod() === 'post')
{
if($this->validationRules)
{
if (!$this->validate($this->validationRules)) //set the rules
{
$this->dataResponse['form'] = $this->form($this->form,TRUE);
echo view('admin/base',$this->dataResponse);
}
else
{
$this->save($this->model);
}
}else
{
$this->save($this->model);
}
}else
{
$this->dataResponse['form'] = $this->form($this->form);
echo view('admin/base',$this->dataResponse);
}
}
}
and does not validate for me, for the same id not work,
Thank you.