![]() |
Model validation - localized labels - 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: Model validation - localized labels (/showthread.php?tid=86191) |
Model validation - localized labels - Rinart - 01-19-2023 I'm trying to validate input data when creating a new client but I want to properly display localized messages along with the field names: Code: // Validation The problem is that apparently it's not allowed to call functions in protected variable definition in a model class (I'm getting "Fatal error: Constant expression contains invalid operations"). Currently I'm using the following workaround. Is it ok? Code: $rules = $model->getValidationRules(); And how do I display model errors in a place where form validation errors usually are? Right now I'm using the following: Code: if ($model->insert($inputs, false) === false) { RE: Model validation - localized labels - kenjis - 01-19-2023 You can move the initialization of $validationRules to the initialize() method of the model. |