dpbfb7119 2015-11-26 03:08
浏览 76
已采纳

如何在找不到类时加载默认控制器

Is it possible to setup CI such that when a URI match is made it follows the standard method of calling the method of the matched class, but when no class is matched, it calls the default class instead?

For instance, lets say I have the following controllers defined:

controllers/main.php
controllers/page1.php
  • When the URI is localhost/Main then controllers/main.php class matches (standard CI)

  • When the URI is localhost/ then the controllers/main.php class matches (assuming default controller is defined in config/routes.php)

  • When the URI is localhost/Page1 then the controllers/page1.php
    class matches (standard CI)

  • When the URI is localhost/Undefinedpage then I want the
    controllers/main.php to be matched.

Note I can't list this explicitly in the config/routes because I don't know what the actual text is.

I also don't want to do wild-card match because it would prevent the normal operation of CI. I also don't want to setup a route for each controller - that would be silly.

A 404 over-ride is close to the operation I want, but the 404-override doesn't prevent a 404 from being issued - so that solution is not valid either.

Thanks for your suggestions.

  • 写回答

1条回答 默认 最新

  • drf65218 2015-11-26 03:42
    关注

    In config/routes.php

    $route['404_override'] = 'controllers/main';
    

    when ever user visits some other URL, CI will ditect that as 404 and redirect to above controller

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

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀