Welcome Guest, Not a member yet? Register   Sign In
add an ID automatically to URL
#1

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)
ressan.ir
CI is nice Heart
Reply
#2

(This post was last modified: 05-05-2015, 08:30 AM by nasser.man.)

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  
--------------------------------------------------------------------------------------------
0       home         /default          any                          0
1       login          /users/login    unauthenticatd          0
2       logout        /users/logout  authenticated            0

....


table menu slugs :


Code:
ID          id_menu                    slug        
-----------------------------------------------------------------------
x           0                               home-page
x           0                               default-page
x           1                               login-page
x           2                               logout-me


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,
ressan.ir
CI is nice Heart
Reply
#3

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'
into config/routes.php.

In that controller you can handle the requests any way you want by writing logic for specific cases you have.

Hope this will help.
Reply
#4

your solution really helped me Smile 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 Wink , 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.
ressan.ir
CI is nice Heart
Reply
#5

Sure. Nothing stops you of doing this. It'll work like a charm Wink
Reply




Theme © iAndrew 2016 - Forum software by © MyBB