简体   繁体   English

如何在网站中形成动态导航

[英]How can I form dynamic navigation in my site

I have a numerous amount of routes a user could take in my site, for example if they are one particular user, they get different navigation compared to another user. 我有很多用户可以在我的站点中使用的路线,例如,如果他们是一个特定用户,则与另一个用户相比,他们将获得不同的导航。

Dependant on what sector a user is, I have created a switch statement to capture these id's and construct their unique navigation titles: 根据用户所在的部门,我创建了一个switch语句来捕获这些ID并构造其唯一的导航标题:

switch($sector_id){
    /*chefs
    case 'f8721714d845eaa5222dcdb4dd642ceb29a280bc':
        $key_array= array('menus','news','staff','directory');
        $url_array = array('/dashboard/menus/','/dashboard/news2/','/dashboard/staff2/','/dashboard/directory2/');
        $name_array = array('Menus2','News2','Staff2','Directory2');'Recipe Stories', 'Blog', 'Events');
        break;*/
    //restaurants, pubs
    case 'c835ff2d2838b3ea45bdb729c641b73b4fa0098d':
    case '378ee5253530d7d02cea3012966deab24bcc5da2':
        $key_array= array('menus','news','staff','directory');
        $url_array = array('/dashboard/menus/','/dashboard/news/','/dashboard/staff/','/dashboard/directory/');
        $name_array = array('Menus','News','Staff','Directory');
        break;

So for example this is what I already have (hard coded): 例如,这就是我已经拥有的(硬编码):

array(  'key'   =>  'profile',
        'url'   =>  '/dashboard/profile/',
        'name'  =>  'Profile'),
array(  'key'   =>  'picture',
        'url'   =>  '/dashboard/picture/',
        'name'  =>  'Profile Picture'),
array(  'key'   =>  'cv',
        'url'   =>  '/dashboard/cv/',
        'name'  =>  'CV').

How can I dynamically construct the arrays above? 我如何动态构造上面的数组? I could use a for each statement, but their would have to be nested right? 我可以对每个语句使用a,但是必须将其嵌套对吗? Any help would be appreciated. 任何帮助,将不胜感激。

Thanks 谢谢

have you thought about creating static navigation html for each user type and just including the file base on user type? 您是否考虑过为每种用户类型创建静态导航html,而仅包括基于用户类型的文件? This would may be easier for you if you don't want to go "All Out" on dynamic navigation. 如果您不想在动态导航上“全力以赴”,这对您可能会更容易。 Your hard coding your navigation anyway... 无论如何,您都要对导航进行硬编码...

or 要么

If you want to be truly dynamic, store all of your navigation items in a table (id, key, url, name) and create a join table for user type and navigation items. 如果要真正做到动态,请将所有导航项存储在一个表中(ID,键,URL,名称),并为用户类型和导航项创建一个联接表。

Join Table Columns: (usertype, navigation_id) 联接表列:(用户类型,navigation_id)

Join Table SQL (not tested) 联接表SQL(未经测试)

SELECT * FROM usertype_navigation un JOIN navigation_items ni on un.navigation_id = ni.id WHERE un.usertype = "c835ff2d2838b3ea45bdb729c641b73b4fa0098d"

This will return all the navigation items, loop through each record and spit out the html for the navigation item. 这将返回所有导航项,遍历每条记录,并为导航项吐出html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM