Language file in rule group error? |
Is there a way to be able to use a lang() in a rule group to display errors?
In my Config/Validation.php PHP Code: public $clientRegistration = [ I am getting an error in my IDE: "expression is not allowed as field default value" Maybe I am missing on how to do this. Thank you in advanced.
Yes and there are two ways how to achieve it, I'll explain you the easy way.
First, you are facing your problem because in PHP you cannot run methods when doing class properties declaration out of constructor scope. You are trying to declare it as public variable. Instead describe your validation rules when class gets constructed: PHP Code: <?php The hard answer would be to create your intermediate class that extends CI Model Class and then when creating your models you call your intermediate constructor with all parameters that get passed to CI Model Class. A brief example: PHP Code: class YourModel extends IntermediateClass In the long run you would benefit from your IntermediateClass simply cause you have the freedom to extend your "base model" without interfering with CI native code.
Thank you for your response.
So the short answer is "no." You cannot use the lang() function in the Validation config file. I know I can do it in the Controller but the purpose of the Validation config file (to my knowledge) is to store all those validation rules there and not the controller (or model). Thank you for explaining why. (12-20-2021, 03:18 PM)stopz Wrote: Yes and there are two ways how to achieve it, I'll explain you the easy way.
|
Welcome Guest, Not a member yet? Register Sign In |