add an ID automatically to URL - 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: add an ID automatically to URL (/showthread.php?tid=61662) |
add an ID automatically to URL - nasser.man - 05-04-2015 i am working on a simple content management system, i have a menu that contains urls and any needed task (controllers), like : ID title url permission parent_id .... 1 home / any 0 2 login /user/login unauthenticated 0 ... 10 task1 /controller/task1 any 0 11 task2 /controller/task2 any 0 12 task2_alt /controller/task2 any 0 my problem is :how i can add page_id or menu_id to url using routes so in every get that id? i want to use that id in my template class for adding widgets to page, ex. in menu_id : 11 i have widget_a , and in menu_id : 12 widget_a and widget_3 in face controller/task2 is same in two menu_item but page_id of them id different, i need something like this in routes : user type "site/ index.php/ 12/ controller/ task2/ bluh/ bluh" that 12 is a number (id of menu_id) RE: add an ID automatically to URL - nasser.man - 05-05-2015 i think it can be done in better way : new table that contains slugs for menu items : table menu items : Code: ID title url permission parent_id .... table menu slugs : Code: ID id_menu slug in this case when user types one of this URLs, must be routes to /default controller : /default /home-page /default-page i think joomla uses same way (i think) , now my problem is " how i can get this rules from database and add them to config/routes.php dynamically at runtime,? //---------------------------------------------------------- $route['home-page'] = 'default'; $route['default-page'] = 'default'; //---------------------------------------------------------- i use wiredesignz / codeigniter-modular-extensions-hmvc in my application, RE: add an ID automatically to URL - codinghamster - 05-05-2015 Hi. It seems like your situation can be solved in a different manner. Thanks to the HMVC extension you use, controllers can be called programmatically. You know, this way: PHP Code: Modules::run('module/controller/method', $param, $...); So you can route all the requests to some dedicated controller by putting PHP Code: $route['.*'] = 'router_controller/method'; In that controller you can handle the requests any way you want by writing logic for specific cases you have. Hope this will help. RE: add an ID automatically to URL - nasser.man - 05-05-2015 your solution really helped me tank you codinghamster, in fact i want to add ability to use widgets in my application, it needs to know witch page is displayed for user, menu_id is one way (like joomla cms), but i think it is possible to use alias names for menu items ( and any task / url ) and find menu_id by using that alias name, your post is helpful, i get it , but is it possible to use an controller/method in module as rooter method? like Code: $route['page/.*'] = 'site_core_module/router_controller/route_method'; in this way i can pack site_core controllers/... in separated module, now i use a controller in application/router_controller/route_method. RE: add an ID automatically to URL - codinghamster - 05-06-2015 Sure. Nothing stops you of doing this. It'll work like a charm |