![]() |
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]Lorin[/eluser] I know, but that was only for show simple example. You can rewrite it with your recursive code. I will should try to code it, but I'm CI newbie. Don't wait anything. my own helper creating menu - El Forum - 08-13-2011 [eluser]InsiteFX[/eluser] Your helper does not work because your function name is different then the function_exists name! You need to give them both the same name! Also if your use function helpers and you want to use like CI's database then you also need to use the CI Super Object! Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); InsiteFX my own helper creating menu - El Forum - 08-14-2011 [eluser]Krystian[/eluser] Thank you for you reply InsiteFX. This is my 2nd project in CI. Two more questions: 1. I autoload create_menu in config file and when in controller Code: $data['menu'] = create_menu(0, 1); Fatal error: Using $this when not in object 2. Is it good convention/idea to code all my old ( I pasted it somewhere above ) function into helper? with html tags etc... 3. And more important now is that I don`t know how to use recursive helper can you please give me example pseudo code how to do this? my own helper creating menu - El Forum - 08-14-2011 [eluser]InsiteFX[/eluser] 1)For a helper like that you need to load it in your controller. Your controller is the object. If you need it across multiple controllers use a MY_Controller. 2) No you should not have html code in it unless you create. 3) A recursive function just calls itself. Code: function getChild($id) InsiteFX my own helper creating menu - El Forum - 08-14-2011 [eluser]Krystian[/eluser] yeah but I get this error in helper file Fatal error: Using $this when not in object context in C:\wamp\www\application\helpers\create_menu_helper.php on line 9 Code: $query = $this->CI->db->get('menu'); my own helper creating menu - El Forum - 08-14-2011 [eluser]InsiteFX[/eluser] Thats because your model is not in the helper! InsiteFX my own helper creating menu - El Forum - 08-15-2011 [eluser]Krystian[/eluser] ok, try to not hate me ![]() look I don`t know how to use your tips and try to do this in model just for test with html tags model Code: function getMenu($parent, $level) in controller Code: $data['menuHTML'] = $this->menu_model->getMenu(0, 1); in view simple echo $menuHTML and it seems like recursive function is not working because I get only the first level. And notice undefined var menu ;/;/ BUT of course I would like to do in helper my own helper creating menu - El Forum - 08-15-2011 [eluser]InsiteFX[/eluser] I would make into Class Library! Thats how I do mine. InsiteFX my own helper creating menu - El Forum - 08-15-2011 [eluser]Krystian[/eluser] ok, based on your previous advices library, I used CI super object Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); then in controller Code: $data['menu_header'] = $this->mymenu->create_menu(0, 1); Why I get Undefined variable: menu ( this is not a problem, but why when I code in the first line var $menu = '' I get parse error ? and when $menu = '' not? all systems libraries have got var ) |