【问题标题】:how to trim url with php codeigniter如何使用 php codeigniter 修剪 url
【发布时间】:2018-04-25 01:58:54
【问题描述】:

如何去除下图中的标记?此 url 用于创建博客详细信息。我使用这种 php codeigniter 语言

图片如下:

【问题讨论】:

标签: php codeigniter


【解决方案1】:

如果您应该从 URL 中删除字符串,这可能会对您有所帮助。

  • 通过使用parse_url() 解析URL 将其作为一个数组。
  • 提取字符串的一部分,然后使用parse_str() 分解它。
  • 使用unset删除参数。
  • 现在使用http_build_query() 构建您的网址。

这将为您提供您应该执行的 URL。

其他方式:

如果您想通过优化它来使用该 URL,请使用 CodeIgniter 的routes 功能。请在下面检查。

路径: application/config/routes.php/

$route['your_url_string'] = 'blog/detail';

【讨论】:

    【解决方案2】:

    像这样添加

    在 application/config/ruotes.php 中

    $route['(.*)'] = 'YourController/YourMethod'; // example 'blog/detail'
    

    在您的控制器中 - 我猜Blog 是控制器,detail 是方法

    class Blog extends CI_Controller{
        public function __construct(){
            parent::__construct();
        }
        public function detail(){
            $id = $this->uri->segment(1); // return 8
            $slug = $this->uri->segment(2); // return 77-anniversary
        }
    }
    

    可见

    <a href="<?=base_url('8/77-anniversary');?>">Title</a>
    

    【讨论】:

      猜你喜欢
      • 2011-03-05
      • 2010-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 2018-03-11
      • 2011-02-01
      • 1970-01-01
      相关资源
      最近更新 更多