代码点火器中的跳跃控制器
我想要一种动态路由的形式。
基本上我想捕获404(通过routes.php 404_override完成)。
这很容易。
但接下来我想做的是进行一系列检查。
例如不要注意is_xxx
函数不是来自任何地方
$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');
}
这是一个非常基本的例子!
所以我的问题是, 一旦做出决定,我将如何重新路由到其他控制器?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从广义上讲,使用 CodeIgniter 执行此操作有点混乱。来自 java 领域的 RequestDispatcher.forward() 负责处理这些事情,但在 PHP 空间中,它通常是一个 redirect():通常没有服务器端基础设施来(有效地)将请求从一个 PHP 文件传递到另一个文件无需客户端往返。
透过 Google 的视角:http://codeigniter.com/forums/viewthread/55212/P15/< /a> 是与 CI 助手进行的长时间讨论,声称可以让您执行此操作, http://codeigniter.com/wiki/Wick/ 是一个看起来确实可以做到这一点的库。
让我知道其中任何一个是否有效:您可能最好将它们重构出来,但这确实会在一段时间后变得乏味,所以我可以理解将处理传递给另一个控制器的愿望(如果您愿意,为什么还要费心往返)不必)。
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).