• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI4 Validation is_unique in properties Config/Validation

#1
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".



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.
Hernan Rodríguez
herodsoft@gmail.com
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.