Need help: Language files. |
[eluser]heavener[/eluser]
Hi everyone. I am literally brand new with CodeIgniter. I am just trying to build my very first application and am having trouble with the Language files. I need a file that I can load all of my global language keys in to, like the Site Name, repetitive sentences, etc., and then I'd like to be able to fetch the line of language from any view file. I looked at this: http://ellislab.com/codeigniter/user-gui...guage.html I found that it shows me how to create language files, and I understand how to load my language file, but how do I echo it on my view page? Can someone help me with this? :question: Thanks.
[eluser]pistolPete[/eluser]
The user guide describes that as well: Quote:Fetching a Line of Text
[eluser]heavener[/eluser]
Mhm, I know what you mean, and I've tried that. But none of my echo statements seem to work. I'll show you what I mean... Here is my controller: Code: <?php And now I know I'm supposed to echo it in my corresponding View file, so here's what I've tried: Code: <?=$lang['site_title']?> Code: <?=$site_title?> But those just don't work! I just get that typical PHP "Undefined variable" error. What should I do? Thanks.
[eluser]pistolPete[/eluser]
You didn't assign the variable. Code: function index() In your home_header view: Code: <?php echo $site_title; ?> Have a look at the user guide: http://ellislab.com/codeigniter/user-gui...views.html
[eluser]xwero[/eluser]
The best way to use language strings in your views is by loading the language helper and in the views you can do Code: <?php echo lang('site_title') ?>
[eluser]JulianM[/eluser]
Moreover, if you want to avoid write $this->lang->line each time, you can create a simple helper. Good luck. Julian [quote author="pistolPete" date="1235837361"]The user guide describes that as well: Quote:Fetching a Line of Text[/quote]
[eluser]TheFuzzy0ne[/eluser]
Such a helper exists already. It's the [url="http://ellislab.com/codeigniter/user-guide/helpers/language_helper.html"]language helper[/url]. You'd use it like this: Code: <?php echo lang('site_title'); ?> EDIT: Err... As xwero suggested... |
Welcome Guest, Not a member yet? Register Sign In |