Welcome Guest, Not a member yet? Register   Sign In
validation
#1

(This post was last modified: 02-02-2023, 04:42 AM by devo.)

how to use custome validation in model??

i have tried and followed the documentation but i am getting the following error

the documentation i follow : 

model validation
validation


this is my validation file code App\Validation :
Code:
<?php

namespace App\Validation;

class Administrators
{
    public $administrator = [
        'full_name'    => 'required',
        'username'    => 'required',
        'email'        => 'required|valid_email',
        'password'    => 'required',
        'password_confirmation' => 'required|matches[password]',
    ];
}


this is my model 

PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
AdministratorModel extends Model
{
 
// Validation
 
protected $validationRules      'administrators';
 protected 
$validationMessages  = [];
 protected 
$skipValidation      false;
 protected 
$cleanValidationRules true;

 
// Callbacks
 
protected $allowCallbacks true;
 protected 
$beforeInsert  = [];
 protected 
$afterInsert    = [];
 protected 
$beforeUpdate  = [];
 protected 
$afterUpdate    = [];
 protected 
$beforeFind    = [];
 protected 
$afterFind      = [];
 protected 
$beforeDelete  = [];
 protected 
$afterDelete    = [];



this is my controller :

PHP Code:
<?php

namespace App\Controllers\Administrator;

use 
App\Controllers\BaseAdministratorController;

class 
Administrator extends BaseAdministratorController
{
private 
$model;

public function 
initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
parent::initController($request$response$logger);
$this->model model("App\Models\AdministratorModel");
}

/**
* Create a new resource object, from "posted" parameters
*
* @return mixed
*/
public function create()
{
$data $this->request->getPost();

echo 
'<pre>';
print_r($this->model->save($data));
echo 
'</pre>';die;
}

Reply


Messages In This Thread
validation - by devo - 02-02-2023, 04:41 AM
RE: validation - by kenjis - 02-02-2023, 05:02 AM
RE: validation - by devo - 02-02-2023, 05:25 AM
RE: validation - by kenjis - 02-02-2023, 05:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB