Codeigniter will not load language

不想你离开。 提交于 2020-01-03 00:41:10

问题


Hello i have problem with Codeigniter language class.

I follow this guide :

https://www.codeigniter.com/user_guide/libraries/language.html

I create test controller

I create test_lang.php inside app/language/english

I set english language in config file

My controller :

<?php

    class Test extends MX_Controller
    {
        public $data;

        function __construct() 
        {
            $this->load->helper('language');
            $this->load->lang('test');
        }

        function index() {

            $this->data['title'] = $this->lang->line("test");

            $this->load->view('test',  $this->data);
        }
    }
    ?>

Application/language/english/test_lang.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$lang['test'] = 'This form post did not pass our security checks.';


?>

Views :

<?php

echo $title;
?>

And i have blanko page. No result, nothing is heppenging.

I try directly in views to put echo $this->lang->line("test"); and again nothing.

What i do wrong? Any1 can tell me how to fix this? Thanks


回答1:


You should load the language file by using $this->lang->load('test'); instead of $this->load->lang('test');.

Update:

There are some mistakes in your controller, first __constructor() must be changed to __construct(). Second, you should call the parent __construct() method after overriding:

public function __construct()
{
    parent::__construct();
}


来源:https://stackoverflow.com/questions/18084284/codeigniter-will-not-load-language

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!