Array problem in 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: Array problem in view (/showthread.php?tid=17159) |
Array problem in view - El Forum - 03-27-2009 [eluser]webscriptz.be[/eluser] Hi, I'm writing a system for a webhoster and it needs a language system from the database so i made my db(mysql) and have everything. Ci retrieves it and puts it into the view as an array. model settings.php Code: <?php controller frontpage.php Code: <?php view Code: <p>$data variable</p> I was hoping i could do the following thing in CI: $lang[id]["diffenrent things here"]; because i need them in a template. So anybody any idea? And don't tell me CI language helper is easier to use because i need it to be really agile and adding languages on the fly through an interface. Array problem in view - El Forum - 03-27-2009 [eluser]TheFuzzy0ne[/eluser] Assuming id is the ID of the language, why are you loading all of your languages at once, instead of just loading the language you need? EDIT: I take that back. I was a bit confused by your code. Array problem in view - El Forum - 03-27-2009 [eluser]TheFuzzy0ne[/eluser] I think I understand the question, and I think this is your answer: Code: foreach ($Q->result_array() as $row){ I'd also suggest you use a helper for selecting the key you want, otherwise you will find you have to use isset() a lot or you may end up with warnings. Also, I noticed that your original version of my code above attempts to access an object, when the result is an array. Array problem in view - El Forum - 03-27-2009 [eluser]webscriptz.be[/eluser] I select all the values from "langv" where foreign key lang_id is selected from "langs" and only the one where status is 1. as for the code: I'don't think it's the solution,(sorry), basically I want to do something like smarty does with smarty->assign() so that I can easily take them in the tpl my langv is id - name and value and I was thinking of parsing for each name, the same variable with the value in it. Array problem in view - El Forum - 03-27-2009 [eluser]TheFuzzy0ne[/eluser] Why not use smarty? http://devcha.blogspot.com/2007/12/smarty-as-template-engine-in-code.html Array problem in view - El Forum - 03-27-2009 [eluser]webscriptz.be[/eluser] I like the CI system and smarty irritates me. Array problem in view - El Forum - 03-28-2009 [eluser]webscriptz.be[/eluser] after trying I gave up on smarty but I tried your solution a last time and it works fine now so Thank you! |