dynamic navigation in php

前端 未结 3 644
[愿得一人]
[愿得一人] 2021-01-03 16:37

How do i implement a dynamic navigation in php?

e.g

Home | about | contact | faq | tutorials

i need to automatically generate the links dynamically

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-03 17:08

    i agree with the first solution even if its a bit simply. For me you have to split your website into some script where you include your navigation script like the second solution.

    but if you really want to make a dynamic navigation, your data cant be write in a file and they are stock in a database or on an xml file.... to do that you have to create a class or a function who parse your data and create array like first solution.

     /* header.php (main header template)*/
    
    
    ...
    
    
         
    

    and in another script you have to create a class who manage the data

    ';
             $dataFromDataBase = $cnx->getArray('MySqlRequest');
    
             foreach($dataFromDataBase as $menu) {
                  $menuList  .='
  • '.$menu->name.'
  • '; } $menuList .= '
'; return $menuList; } }

i write it fast but i hope i can help some who look for tips to create dynamic menu.

提交回复
热议问题