【问题标题】:Handle URL in CodeIgniter在 CodeIgniter 中处理 URL
【发布时间】:2013-05-12 23:29:47
【问题描述】:

我有一个类似

的网址

“www.site.com/index.php/details/productname”

我在 codeigniter 中的该链接上收到 404 错误,但 URL www.site.com/index.php/details/ 工作正常。我想以 seo 方式处理 url 参数。

【问题讨论】:

  • 您的问题是什么? CodeIgniter 将期望 productname 成为您的 details 控制器中的一个函数。你想改变什么?
  • 听起来你在做:类详细信息中的“函数索引($productname)”。这是你做不到的。它是否正确?如果是这样,我可以向您展示使用/不使用路线的正确代码
  • 我想在细节控制器中添加一个动态函数名。最主要的是我想在 url 部分传递唯一的产品名称

标签: codeigniter url url-rewriting


【解决方案1】:

您必须在部分网址中添加 /index/ 段: http://www.site.com/index.php/details/index/productname/


如果你想打开像http://www.site.com/index.php/details/productname/这样的url:

1)你需要定义_remap()方法:

public function _remap($method)
{
    if ($method == 'index')
    {
        $this->viewDetails($this->uri->segment(2));
    }
    else
    {
        $this->default_method();
    }
}

2) 使用application/config/routes.php 文件

$route['details/(:any)'] = "products/viewDetails/$1";

来自用户指南:

  1. routers.php
  2. _remap method

【讨论】:

猜你喜欢
  • 2013-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-16
  • 1970-01-01
相关资源
最近更新 更多