Welcome Guest, Not a member yet? Register   Sign In
Create Model with command line
#1

Hi..
I created model from command line and when i open the model file to edit there is this part which i don't understand.

PHP Code:
protected $cleanValidationRules true

Can anyone give explanation or point out the documentation on what is it and how to use that part?
I've tried search on the userguide but found nothing, or maybe i wasn't looking carefully because i only use the search input with cleanValidationRules text.
Reply
#2

(This post was last modified: 09-26-2022, 01:00 AM by InsiteFX. Edit Reason: Spelling error got new keyboard now. )

I had to look at the system/BaseModel to find it.

PHP Code:
/**
    * Whether rules should be removed that do not exist
    * in the passed in data. Used between inserts/updates.
    *
    * @var bool
    */
    protected $cleanValidationRules true
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

It seems the functionality is not documented.

See the source code.
https://github.com/codeigniter4/CodeIgni....php#L1340
Reply
#4

Thanks @kenjis , @InsiteFX
So looking at your pointers does it means that if set to true then whenever we pass request data on model for easy to insert/update it will only validate only matching field/rules name on request data?
Does it also works not only on model but on every time we use validation library? I was thinking if i can make that some global validation that have all rules saved on validation config or separate files.
Sorry for my bad english.
Reply
#5

(This post was last modified: 09-25-2022, 02:24 PM by kenjis.)

If $cleanValidationRules is true, the validation rules for the field that is not contained in the passed data will be removed before validation.

But it does not seems to work if you don't call validate() by yourself.
If you call insert() or update() or save(), the $cleanValidationRules value will be changed automatically.
I'm not sure this is a bug or not.

Anyway, it is a feature in Model, not in the Validation library.
Reply
#6

(09-25-2022, 02:20 PM)kenjis Wrote: If $cleanValidationRules is true, the validation rules for the field that is not contained in the passed data will be removed before validation.

But it does not seems to work if you don't call validate() by yourself.
If you call insert() or update() or save(), the $cleanValidationRules value will be changed automatically.
I'm not sure this is a bug or not.

Anyway, it is a feature in Model, not in the Validation library.
Yes, i think it is a bug too. I tried and get the same result also. There would be no use to put $cleanValidationRules in model if it gets replaced automatically on calling model insert/update/save. The only way it would works if we capture the validation error on validate() then stop executing next line.
Is there any other workaround?
Reply
#7

(09-25-2022, 08:23 PM)[email protected] Wrote: Yes, i think it is a bug too. I tried and get the same result also. There would be no use to put $cleanValidationRules in model if it gets replaced automatically on calling model insert/update/save.

Agreed.
Okay, I will fix it as a bug.
Reply
#8

I sent a PR.
https://github.com/codeigniter4/CodeIgniter4/pull/6588
Reply
#9

Thank you @kenjis
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#10

Thank you all for helping me
Reply




Theme © iAndrew 2016 - Forum software by © MyBB