duaiwu8385 2012-07-25 17:52
浏览 67
已采纳

codeIgniter导航基础知识

How do you make a simple navigation in Code Igniter? I keep tripping up on all these pseudo folders. Originally I was looking to make something that dug through a folder and grabbed all the file-names, then placed them in an array to order them into a nav bar.

Problem is, it seems that CI uses public functions for the pseudo folder in each page. Such as "public function aboutme()" would work out to xxx.xxx.xxx.xxx/index.php/[classname]/aboutme. This poses a problem for me, because when making links like test works out to xxx.xxx.xxx.xxx/[classname]/contactme.

Is there a better, dynamic way to make a nav bar without using a database? I CAN use a database, but I'm trying to learn CI and since I'm already well-versed in MySQL I wanted to find a way to do this some other way.

  • 写回答

1条回答 默认 最新

  • douluozhan4370 2012-07-25 18:00
    关注

    Maybe a custom route would help you?

    http://codeigniter.com/user_guide/general/routing.html

    I'm not sure the structure of your application, but if you are using multiple controllers, it won't really help and there isn't really an easy way to do it "automagically". The best thing would be to come up with some way to manage the navigation items, such as a database (as you said).

    If you're only using one class, you can use PHP's get_class_methods() on the class.

    $pages = get_class_methods('classname');
    
    foreach($pages as $page)
    {
        echo anchor($page, ucfirst($page));
    }
    

    This is a very simplistic way to do it, and you'll have to filter out private methods and the __construct method as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端