doulongti5932 2011-04-27 00:21
浏览 45
已采纳

在代码点火器中跳跃控制器

I am wanting to have a form of dynamic routing.

Basically I want to catch the 404 (done through routes.php 404_override).

This is easy enough.

But then what I want to do is run through a series of checks.

e.g pay no attention to the fact the is_xxx functions are not coming from anywhere

$what = $this->uri->segment(1);
if(is_vanity_name($what)){
    //now I want to route this to the profile controller and call the display function like so 
    //display('vanity', $what);
}
elseif(is_region_name($what)){
    if(($deal = $this->uri->segment(2)) !== false){
        //now I want to route to the deals controller can call the display function like so
        //display($deal, $what);
    } 
    else {
        //now I want to route to the deals controller and call the daily function like so
        //daily($what);
    }
}
elseif(is_deal_name($what)){
    //now I want to route to the deals controller and call the display function like so
    //display($what);
}
else{
    $this->load->view('errors/404');
}

And thats a pretty basic example!

So my question is, How would I go about re-routing to the other controllers once the decision has been made?

  • 写回答

1条回答 默认 最新

  • dtnnpt11795 2011-04-27 01:30
    关注

    Broadly speaking, its kind of messy doing this with CodeIgniter. Coming from java land the RequestDispatcher.forward() takes care of these sorts of things, but in PHP space its usually a redirect(): there typically isn't the server side infrastructure to (effectively) pass requests from one PHP file to another without the client-side round trip.

    Looking through Google's eyes: http://codeigniter.com/forums/viewthread/55212/P15/ is a long discussion with a CI helper that claims to let you do this, http://codeigniter.com/wiki/Wick/ is a library that appears to actually do it.

    Let me know if either of those work out: you might be better off refactoring those out, but that does get tedious after awhile so I can understand the desire to just pass the handling off to the other controller (why bother round-tripping if you don't have to).

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

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动