_remap或URI在codeigniter中路由 [英] _remap or URI Routing in codeigniter

查看:115
本文介绍了_remap或URI在codeigniter中路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在调查PHP框架Codeigniter,并了解到目前为止的主要概念,直到控制器部分关于_remapping。我理解_remapping如何覆盖控制器方法在URI上的行为,例如从www.example.com/about_me到www.example.com/about-me。我想听到的是人们对什么使用_remapping方法或URI路由方法的意见?我只是要求这是因为当研究这些方法和某人困扰重新映射函数,他们已被指示使用URI路由。



So ..



1)使用的主要常用方法是什么和pro的对另一个?
2)最好使用PHP5 CI版本2以上的URI路由吗?



我非常感谢您的意见!

解决方案

假设你不想使用 index (ie http://www.yourdomain.com/category )操作您的类别控制器,您可以使用路线。

  $ route ['category /(:any)'] ='category / view / $ 1' ; 

然后,你只需要在你的类别控制器中使用一个View动作接收类别名称, / p>

http://www.yourdomain.com/category / PHP

  function View($ Tag)
{
var_dump ;
}

如果您仍然希望在控制器中访问索引操作,通过访问http://www.yourdomain.com/category/index


I am currently looking into the PHP Framework Codeigniter and understand the main concepts so far until the Controllers section about _remapping. I have a understanding how _remapping overwrites the behaviour of controller methods over the URI eg from www.example.com/about_me to www.example.com/about-me. What i would like to hear is peoples opinions on what to use- _remapping method or the URI Routing method? Im only asking this as when researching these methods and someone has been troubled on remapping functions, they have been directed to use URI Routing.

So..

1) What is the main common method to use and the pro's over the other one? 2) Is it best to use URI Routing for PHP5 CI version 2 onwards?

I would be grateful to hear your opinions!

解决方案

Assuming you do not want to use the index (i.e. http://www.yourdomain.com/category) action of your Categories controller, you can use routes.

$route['category/(:any)'] = 'category/view/$1';

Then you simply need a View action within your Category controller to receive the Category name, i.e. PHP.

http://www.yourdomain.com/category/PHP

function View($Tag)
{
    var_dump($Tag);
}

Should you still want to access your index action within your controller, you can still access it via http://www.yourdomain.com/category/index

这篇关于_remap或URI在codeigniter中路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆