Welcome Guest, Not a member yet? Register   Sign In
Cannot load Language Files from module
#1

Hi
I followed the instructions https://bcit-ci.github.io/CodeIgniter4/g...dules.html but cannot load language .
Can you help me
Thanks all
Reply
#2

You need to provide details of what you tried, how your code is setup, and what happened for us to be able to help.
Reply
#3

In the model, the error messages of the validation, give an error if you try to use the lang helper.
Reply
#4

(03-08-2018, 07:39 AM)dannywebdev Wrote: In the model, the error messages of the validation, give an error if you try to use the lang helper.

I think that you are trying something like that:

PHP Code:
<?php namespace App\Models;

use 
CodeIgniter\Model;

class 
UsersModel extends Model
{
    protected 
$table 'users';
    protected 
$allowedFields = ['email'];
    protected 
$validationRules = [
        
'email' => 'valid_email'
    
];
    protected 
$validationMessages = [
        
'email' => [
            
'valid_email' => lang('File.arrayKey'),
        ]
    ];


Then:


Quote:ErrorException #64

Constant expression contains invalid operations


PHP  does not allow this.


You will need to call the lang() inside the constructor:

PHP Code:
<?php namespace App\Models;

use 
CodeIgniter\Model;

class 
UsersModel extends Model
{
    protected 
$table 'users';
    protected 
$allowedFields = ['email'];
    protected 
$validationRules = [
        
'email' => 'valid_email'
    
];
    protected 
$validationMessages = [
        
'email' => [
            
'valid_email' => 'Opsss! We need a valid email.',
        ]
    ];

    public function 
__construct(...$params)
    {
        
parent::__construct(...$params);

        
// Override the "Opsss! We need a valid email."
        
$this->validationMessages['email']['valid_email'] = lang('Validation.timezone');
    }

Reply




Theme © iAndrew 2016 - Forum software by © MyBB