• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.