CodeIgniter Forums
What is wrong with this code? Why the language doesn't load? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: What is wrong with this code? Why the language doesn't load? (/thread-40269.html)



What is wrong with this code? Why the language doesn't load? - El Forum - 04-04-2011

[eluser]ReyPM[/eluser]
Hi every:
I'm trying to load a language files but I'm getting this error:
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: User::$lang
Filename: controllers/user.php
Line Number: 6
Where line number 6 is this:
Code:
5  public function __construct() {
6        $this->lang->load('common');
7        $this->lang->load('user');
8  }
What's wrong here?
Cheers and thx


What is wrong with this code? Why the language doesn't load? - El Forum - 04-04-2011

[eluser]InsiteFX[/eluser]
Try loading the Language class and Language_helper!

InsiteFX


What is wrong with this code? Why the language doesn't load? - El Forum - 04-04-2011

[eluser]ReyPM[/eluser]
You mean in autoload? This:
Code:
$autoload['libraries'] = array('database','session','language','my_usession','encryptdecrypt');
$autoload['language'] = array('spanish');
Doesn't work too


What is wrong with this code? Why the language doesn't load? - El Forum - 04-04-2011

[eluser]Unknown[/eluser]
Hi,

try this:

Code:
public function __construct() {
      $this->load->helper('language');

      $this->lang->load('common');
      $this->lang->load('user');
}



What is wrong with this code? Why the language doesn't load? - El Forum - 04-04-2011

[eluser]InsiteFX[/eluser]
Show the structure of your application/language Directories!

InsiteFX


What is wrong with this code? Why the language doesn't load? - El Forum - 04-04-2011

[eluser]ReyPM[/eluser]
This is the structure of my application/language folder:

- english
index.html
- spanish
common_lang.php
index.html
user_lang.php


What is wrong with this code? Why the language doesn't load? - El Forum - 04-04-2011

[eluser]ReyPM[/eluser]
Well something is really wrong here because I tried to load another library and get the same error:
Quote:Severity: Notice
Message: Undefined property: Brands::$load
Filename: controllers/brands.php
Line Number: 5
The file brands.php is as follow:
Code:
<?php

class Brands extends CI_Controller {
   public function __construct() {
      $this->load->helper('flexigrid');
   }
  
   public function index() {
      if (!$this->my_usession->logged_in) {
         redirect('user/login');
      }
      $data['title'] = 'Admin Brands';
      $this->load->view('brands/index', $data);
   }
  
}
I'm using Code Igniter 2.0.1 in XAMPP for Windows 7


What is wrong with this code? Why the language doesn't load? - El Forum - 04-04-2011

[eluser]ReyPM[/eluser]
Well I found the error just need to inherit from Controller constructor:
Code:
public function __construct() {
      parent::__construct();
      $this->load->helper('flexigrid');
}