[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');
$this->view->set('title', $page);
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');
require(APPPATH.'libraries/application'.EXT);
class Dashboard extends Application {
public function __construct()
{
parent::Application();
$this->lang->load('dashboard', 'en_us');
}
public function index()
{
$component = $this->lang->line('dashboard_component');
$page = $this->lang->line('dashboard_title');
$this->view->set('title', $page);
$this->view->set('component', $component);
$this->view->part('tree', 'tree');
$this->view->part('navigation', 'navigation');
$this->view->part('tabpanel', 'tabpanel');
$this->view->part('content', $component);
$this->view->part('properties', 'properties');
$this->view->part('output', 'output');
$this->view->load('complex');
}
}
?>
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>
<head>
<title><?=$title ?></title>
<link rel="stylesheet" type="text/css" href="<?=js_url();?>ext/resources/css/ext-all.css" />
<!-- GC --> <!-- LIBS -->
< script type="text/javascript" src="<?=js_url();?>ext/adapter/yui/yui-utilities.js">
< script type="text/javascript" src="<?=js_url();?>ext/adapter/yui/ext-yui-adapter.js">
< script type="text/javascript" src="<?=js_url();?>ext/ext-all.js">
<!-- ENDLIBS -->
<link rel="stylesheet" type="text/css" href="<?=templates_url();?>complex/css/template.css" />
</head>
<body>
<div id ="container">
<?=$tree ?>
<?=$navigation ?>
<?=$tabpanel ?>
<?=$content ?>
<?=$properties ?>
<?=$output ?>
</div>
</body>
</html>