CodeIgniter Forums
Cannot load Language Files from module - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Cannot load Language Files from module (/thread-70173.html)



Cannot load Language Files from module - HTLove - 03-04-2018

Hi
I followed the instructions https://bcit-ci.github.io/CodeIgniter4/general/modules.html but cannot load language .
Can you help me
Thanks all


RE: Cannot load Language Files from module - kilishan - 03-04-2018

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


RE: Cannot load Language Files from module - dannywebdev - 03-08-2018

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


RE: Cannot load Language Files from module - natanfelles - 03-10-2018

(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');
    }