Welcome Guest, Not a member yet? Register   Sign In
Make Validation Config to Extend BaseConfig
#1

I am creating a project which includes so may plug and play modules, I use Registrar to Extend Filters and Some other Configs, But the Validation Config doesn't extend the BaseConfig so I can't add rules to it except I modify it directly. 
It would be nice to place all rules into a $rules property so that different modules can add theirs to it.
e.g
PHP Code:
<?php

namespace Config;

use 
CodeIgniter\Config\BaseConfig;
use 
CodeIgniter\Validation\CreditCardRules;
use 
CodeIgniter\Validation\FileRules;
use 
CodeIgniter\Validation\FormatRules;
use 
CodeIgniter\Validation\Rules;

class 
Validation extends BaseConfig
{
    //--------------------------------------------------------------------
    // Setup
    //--------------------------------------------------------------------

    /**
    * Stores the classes that contain the
    * rules that are available.
    *
    * @var string[]
    */
    public $ruleSets = [
        Rules::class,
        FormatRules::class,
        FileRules::class,
        CreditCardRules::class,
    ];

    /**
    * Specifies the views that are used to display the
    * errors.
    *
    * @var array<string, string>
    */
    public $templates = [
        'list'  => 'CodeIgniter\Validation\Views\list',
        'single' => 'CodeIgniter\Validation\Views\single',
    ];

    //--------------------------------------------------------------------
    // Rules
    //--------------------------------------------------------------------
    public $rules = [
        'login'=>[
            //
        ]
    ];

Reply
#2

I wasn’t even aware! I’m not sure why this isn’t the case, but if you send over a Pull Request it should stir up any relevant discussion on the topic.
Reply
#3

Hi,I also had this problem. I have already created a topic in this link, but no one has sent a reply.
Reply
#4

Now Registrars can add rules.
https://github.com/codeigniter4/CodeIgniter4/pull/5789
Reply
#5

(03-08-2022, 11:18 PM)kenjis Wrote: Now Registrars can add rules.
https://github.com/codeigniter4/CodeIgniter4/pull/5789

Hi,
I am still unable to figure out to use Registrar to extend Validation in modules (without making change to app/Config/Validation.php). May I ask if anyone can share a sample script?
Reply
Reply
#7

(10-14-2022, 05:06 AM)kenjis Wrote: See https://github.com/codeigniter4/shield/b...ar.php#L31
and https://codeigniter4.github.io/CodeIgnit...registrars

Hi,
Thank you very much for a prompt solution.
The issue has been solved (as per your guide).
Regards.
Reply
#8
Big Grin 

It works now  Smile . Thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB