Welcome Guest, Not a member yet? Register   Sign In
Language array file in "sub view"
#1

[eluser]henry178[/eluser]
Hi,
this is mainteplate view:

Code:
<html>
<head>
<title><?= $title ?> - My Site</title>
<link rel="stylesheet" type="text/css" href="/css/main.css" />
</head>
<body>
   <div id="wrapper">
      <div id="header">My Embedded-View Site</div>
      <div id="menu">&lt;?= $menu ?&gt;</div>
      <div id="content">&lt;?= $content ?&gt;</div>
      <div id="footer">&copy; 2006&lt;?php $endyear = date("Y"); if ($endyear != 2006) echo '-'.$endyear; ?&gt; Me</div>
   </div>
&lt;/body&gt;
&lt;/html&gt;


view/menu:

Code:
<ul>

<li><a href="www.site.com">&lt;?= $lang['one'] ?&gt; </a></li>
<li><a href="www.site.com"> &lt;?= $lang['two'] ?&gt;</a></li>
<li><a href="www.site.com"> &lt;?= $lang['four'] ?&gt;</a></li>
<li><a href="www.site.com"> &lt;?= $lang['five'] ?&gt; </a></li>

?&gt;
</ul>


this is my controller:

Code:
$data['lang'] = $this->lang->load(DEFAULT_LANGUAGE, NAME_LANGUAGE);
$data['lang'] = $this->lang->language;
    
$data['menu'] = $this->load->view('menu', true);
$data['title'] = $row['title'];
$data['author'] = $row['author'];
$data['date'] = $row['date'];
$data['body'] = $row['body_text'];
$data['content'] = $this->load->view('article', $article, true);

$this->load->view('maintemplate', $data);


The problem is the language file.... is impossible to use the language array in menu view? Any solutions?
#2

[eluser]danmontgomery[/eluser]
Why not just load the language helper and use lang() instead of lang[]?
#3

[eluser]henry178[/eluser]
[quote author="noctrum" date="1308772526"]Why not just load the language helper and use lang() instead of lang[]?[/quote]

another file language only for the menu?
#4

[eluser]henry178[/eluser]
ah ok! Smile
http://ellislab.com/codeigniter/user-gui...elper.html
#5

[eluser]danmontgomery[/eluser]
[quote author="henry178" date="1308773952"]ah ok! Smile
http://ellislab.com/codeigniter/user-gui...elper.html[/quote]

Yep.

Just so there's no confusion for future visitors, rather than passing the language array to the view to try and access it directly, once the language file is loaded, you can access it with the language library with:

Code:
echo $this->lang->line('example');

You can also load language helper, and just use the lang() function:

Code:
echo lang('example');

In either case, it's unnecessary to pass the language array directly to the view.




Theme © iAndrew 2016 - Forum software by © MyBB