![]() |
Using the language strings in the view - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Using the language strings in the view (/showthread.php?tid=2672) |
Using the language strings in the view - El Forum - 08-17-2007 [eluser]Unknown[/eluser] This might be a stupid question but I found no answer to it. In the controller I use: $this->lang->line('language_key'); but I have no use fo the language strings in the controller, i need them in the view. But what do I use in the view?! Do I have to pass all the language keys in an array to the view or is there something more automatic? Using the language strings in the view - El Forum - 08-17-2007 [eluser]BravoAlpha[/eluser] [quote author="naicuoctavian" date="1187415451"]In the controller I use: $this->lang->line('language_key');[/quote] You can use that in the view too. Using the language strings in the view - El Forum - 08-18-2007 [eluser]esra[/eluser] You can also use Bravo's approach to assign language strings to variables and reuse the variables directly or indirectly as necessary in your controllers and views. Quote: $page = $this->lang->line('dashboard_title'); In your view, you could use: Quote: <title><?=$title ?></title> The second line of the above uses Coolfactor's View library, but many of the other View libraries and template solutions have a similar method for setting variables. The above solution is good if you need to reuse the same variable multiple times within the same controller: You can also do this: Quote: $this->view->set('title', $this->lang->line('dashboard_title'); A more complete example: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); The master view below is composed of multiple view fragments and the $component variable is used multiple times in the controller and view: Code: <html> Using the language strings in the view - El Forum - 08-18-2007 [eluser]Unknown[/eluser] Thks for the reply BravoAlpha. esra the approach you are describing does not seem to appropriate for when one has many language strings, but thks. I personally use Smarty. |