![]() |
Cannot Access Global Variable in Loop - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Cannot Access Global Variable in Loop (/showthread.php?tid=64326) |
Cannot Access Global Variable in Loop - spider58 - 02-08-2016 Hello. Im passed an array and some global variables array to view file. Code: $website_lang_array = array ( if i use this variable a outside of lop such as Code: {LANG15} this is working good. But when i try to access in loop such as Code: {content} This is not working. i think its search {LANG15} in content array. i must acces {LANG15} in loop. but how? Thanks inadvance. RE: Cannot Access Global Variable in Loop - siburny - 02-09-2016 You are right: it's trying to load LANG15 from "content" array rather than main array. I don't think build-in Parser library has a solution for you. But you can use another parser library (I use Mustache myself https://github.com/bobthecow/mustache.php), but it will require additional work of setting it up. P.S. I can send you link to my drop-in version of the library that requires no changes in your code to use it (e.g. $this->parser->parse). RE: Cannot Access Global Variable in Loop - spider58 - 02-13-2016 (02-09-2016, 03:22 PM)siburny Wrote: You are right: it's trying to load LANG15 from "content" array rather than main array. I don't think build-in Parser library has a solution for you. But you can use another parser library (I use Mustache myself https://github.com/bobthecow/mustache.php), but it will require additional work of setting it up. thanks for reply. so, all other users using another parser libraries? this is weird. in a looop i can't access a variable :S this is enough for leave codeignitier. RE: Cannot Access Global Variable in Loop - siburny - 02-14-2016 You can use variable in a loop. You have to put it inside a specific sub-array ("content" in your case). Most people tend to pass to view/parser variables that are needed for that particular template rather then throw everything at it and let template decide if it needs it. RE: Cannot Access Global Variable in Loop - siburny - 02-14-2016 What I suggest you do is use language helper: lang - https://www.codeigniter.com/userguide3/helpers/language_helper.html Then you just load a language file in CI and you don't need to pass anything to a view or parser in this case. |