CodeIgniter Forums

Full Version: core/Lang.php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to extend CI native Lang class to use MySQL Database. My problem is, i cant connect to DB or do $this->load->database or load anything.

I'v tried adding these classes manually like this:

Code:
# Extensions
require_once SYSDIR . '/core/Loader.php';
require_once SYSDIR . '/libraries/Session.php';

Still nothing. I also have Stackoverflows question running but it seems to have downgraded rating, like why? I'v been stuck on this for almost half a week and i cant figure it out.

Very short way to see my problem:

Code:
class JK_Lang extends CI_Lang {
       function __construct() {
        # Loading parent language class functions
        parent::__construct();
        
        # Loading database
        $this->load->database(); // Undefined property: JK_Lang::$load
        
        # Register as loaded
        log_message('debug', 'JK_Lang Class initialized');
    }
}

Fatal error: Call to a member function database() on a non-object in application/core/JK_Lang.php on line 31

PS: I'm very new to CI or any kind of MVC Framework.
In __construct you have to instantiate the ci core like that

PHP Code:
$this->ci =& get_instance();
$this->ci->load->database(); 
(01-27-2015, 02:31 AM)Rufnex Wrote: [ -> ]In __construct you have to instantiate the ci core like that


PHP Code:
$this->ci =& get_instance();
$this->ci->load->database(); 

That won't work. The Lang class is loaded before get_instance() becomes usable.

@stopz

I don't want to go into lengthy details why, but I'll save you some headaches - you can't do that.
Depending on why would you want to use the database on the language file is out of my comprehension but let me give you some ideas.

If you're just pulling info from the file than just call the database from the controller get the info from your database and add it to the $data array to be use in a view.

Now if you're trying to add information to the language file from the database than get the info from the database from your controller and open the language file and add the new data to it and save it this will keep your Language file up to date.

The language file is a simple solution to a simple problem. But depending on what you're trying to do you can just put all your language info into the database and pull it when you want too.

If you really want to use the database on the language file than just connect to it the old fashion way is not that hard.

Or explain a little more on what you're trying to do to see if anyone can come up with a solution.
Related to this topic but off it..

@Narf what do you thing for adding support of different resource types for translations?
I can work over pull request which will add the option to pick between the current .php arrays, .po, .mo files perhaps even json's and any other formats.
It will require different loaders and parsers for each format, not too much work .
It can come inside CI 3.1 or other next version .

And perhaps a db support can be introduced too , although I don't like this option at all..
(01-27-2015, 05:16 AM)sv3tli0 Wrote: [ -> ]Related to this topic but off it..

@Narf what do you thing for adding support of different resource types for translations?
I can work over pull request which will add the option to pick between the current .php arrays, .po, .mo files perhaps even json's and any other formats.
It will require different loaders and parsers for each format, not too much work .
It can come inside CI 3.1 or other next version .

And perhaps a db support can be introduced too , although I don't like this option at all..

No. It may not seem as too much work to you, but it is pointless work.