![]() |
my own helper creating menu - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: my own helper creating menu (/showthread.php?tid=44399) Pages:
1
2
|
my own helper creating menu - El Forum - 08-13-2011 [eluser]Krystian[/eluser] Hi, I`m trying to create dropdown menu from db. Now just for example helper Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); controller Code: <?php view Code: <?php in this simple example I would like to retrieve some data from db using helper. Or maybe I should put it into model and then use model method in helper. Can someone give me a correct tip/code to do this? p.s. my function creating menu Code: <?php Krystian my own helper creating menu - El Forum - 08-13-2011 [eluser]Lorin[/eluser] I'm not sure, that is reason for your problem, but i don't see: Code: $this->load->helper('yourhelper'); Where do you have the third script? Isn't necessary to load it into helper file? my own helper creating menu - El Forum - 08-13-2011 [eluser]Krystian[/eluser] I`m autoloading it. I`m a little bit confused if I can use Code: $this->db->select($query) This function should return an array and then pass to view and loop through it. The third script should be paste into first one -> helper ( now is just for test ) my own helper creating menu - El Forum - 08-13-2011 [eluser]Lorin[/eluser] In helper, you don't have a class. I think you can't use $this->db->get('menu'); my own helper creating menu - El Forum - 08-13-2011 [eluser]Krystian[/eluser] I guess so... so can someone give me a tip/sample code to resolve my issue? Basically I need to have recurive function which creates my menu and display it in view ![]() my own helper creating menu - El Forum - 08-13-2011 [eluser]Lorin[/eluser] What about to use [Models] rather than Helper? my own helper creating menu - El Forum - 08-13-2011 [eluser]Krystian[/eluser] yeah, of course I can create model ( recursive ), but look on my old function again Code: function display_children($parent, $level, $dbh) { This ( with CSS help ) create fine dropdown menu. How can I use it in model? I don`t want to have HTML tags there. my own helper creating menu - El Forum - 08-13-2011 [eluser]Lorin[/eluser] In model, there will be 'get-data' part of scripts. In controller you will parse returned data as you wish and send them to view. That's my opinion at least. my own helper creating menu - El Forum - 08-13-2011 [eluser]Lorin[/eluser] For example I made simple script to create menu from database: model: Code: <?php controller: Code: <?php and view: Code: <html> I know, it is really simple. Note: It's using my 'user' table, because I'm too lazy to create another table for testing. my own helper creating menu - El Forum - 08-13-2011 [eluser]Krystian[/eluser] I`ll try it later but as you can see that my method is a bit different. It`s recursive and has html tags. Try code it ![]() See you later and thanks for your posts |