1

In my PHP websites I’m using SiteTranslator script for a website translated into 30 languages. Each translation is stored in its own table (text_en, text_de...) and each table has 3 columns (textKey, textValue, lastUpdate).

Now I would like to use that database in my CodeIgniter application. What would be the best way to do it?

3
  • 4
    What are you trying to do? To use it, you have to read the CodeIgniter user guide, especially the Database Class part: codeigniter.com/user_guide/database/index.html Commented Sep 6, 2012 at 9:49
  • your question is too broad ,try something specific Commented Sep 6, 2012 at 10:01
  • If you want to use it alongside another database, you can connect to multiple databases. Read more in the documentation. Commented Sep 6, 2012 at 10:58

1 Answer 1

1

You could use multiple databases as suggested, you would still need to setup your app language files

{read more in the user guide}

Based on the first uri segment you could try something like this.

Adding routes

$route['en|fr|gr/test'] = 'test';

First segment checks for en OR fr OR whatever else.

Then the Main Controller catches the first segment before the test controller is initialized and the db(object) && app(language) files are set

www.site.com/en/test => load english language file(application/language/english/mylanguage) and db

www.site.com/fr/test => load french language file(application/language/french/mylanguage) and db ...and so on

Main Controller

class MY_Controller extends CI_Controller{

    protected $lang, $db;

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

        $this->set_language();
    }

    protected function set_language(){
        switch($this->uri->segment(1))
        {
            case 'en':
                $this->lang     = $this->lang->load('mylanguage', 'english');
                $this->db       = $this->load->database('en', TRUE); 
            break;

            case 'fr':
                $this->lang     = $this->lang->load('mylanguage', 'french');
                $this->db       = $this->load->database('fr', TRUE); 
            break;

            default:
                $this->lang     = $this->lang->load('mylanguage', 'english');
                $this->db       = $this->load->database('en', TRUE); 
            break;
        }
    }


}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.