<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Main_model extends CI_Model {
private function get_rules()
{
return [
[
'field' => 'username',
'label' => 'Name',
'rules' => [
'required',
[
'username_callable',
[$this, 'username_check']
],
],
],
[
'field' => 'useremail',
'label' => 'Email',
'rules' => 'required|valid_email',
]
];
}
public function register()
{
$this->form_validation->set_rules( $this->get_rules() );
if($this->form_validation->run() === FALSE)
{
return 'Not registered!';
}
else
{
return 'Registered!';
}
}
public function username_check($username)
{
if($username != 'John')
{
$this->form_validation->set_message('username_callable', 'You must be John!');
return FALSE;
}
else
{
return TRUE;
}
}
}