CodeIgniter Forums
Validation Database Group Definition - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Validation Database Group Definition (/showthread.php?tid=81065)



Validation Database Group Definition - 68thorby68 - 01-20-2022

Hi,
On my Ci4 app I have split my customers tables (prefixed per customer) accross a number of databases and therefore have a number of defined database groups. I control access to the correct database and correct table prefix via session values, populated at login.
I am also using the config\validation.php for my validation rules.
However, one of my validation rules checks the database to validate the data is winthin the defined bounds.
PHP Code:
public $Division = [
  'division' => [
     'rules'  => 'required|is_not_unique[divisions.division_name]',
     'errors' => [
       'required'=> 'Division Required',
       'is_not_unique' => 'Invalid Division.'
     ]
   ],
 ]; 
Is it possible to configure the validation (or rule) away from $default database to another database group?


RE: Validation Database Group Definition - kenjis - 01-20-2022

Try to add 'DBGroup' key and its value in the data to validate.

Try to use `Validation::run()` method with the third param DBGroup.

PHP Code:
run(?array $data null, ?string $group null, ?string $dbGroup null



RE: Validation Database Group Definition - 68thorby68 - 01-21-2022

(01-20-2022, 06:44 PM)kenjis Wrote: Try to add 'DBGroup' key and its value in the data to validate.

Try to use `Validation::run()` method with the third param DBGroup.

PHP Code:
run(?array $data null, ?string $group null, ?string $dbGroup null

Many thanks,

I'll have a play with this as I also need to add the table prefix somewhere along the line.  This is very helpful.

Cheers,
Martin