【发布时间】:2011-09-22 18:09:55
【问题描述】:
我正在使用 CodeIgniter 框架,我对如何从我的网址中删除 %20 感到困惑。下面是我的代码示例。 控制器 - 博客 方法 - 显示 属性 - 这是我的博客
public function show($blog= null)
{
// my attempt to set the uri segment
$blogName = $this->uri->segment(3, url_title($blog));
... //other code
}
这不起作用,我很困惑在哪里实现 url_title('this is my blog') 函数,以便在页面加载时显示:
/blog/show/this-is-my-blog
我需要在 config/routes.php 文件中做些什么吗?
谢谢!
编辑:
好吧,我发现 url_title() 输出 this20is20my20blog 所以我现在有了这个:
$blogUrl = str_replace("%20", "-", $blog);
$this->uri->segment(3, $blogUrl);
但它仍然返回带有 %20 的 URL
【问题讨论】:
-
如果不显示其他代码(例如,什么“返回”%20?),就不可能知道发生了什么。此外,您说您希望它显示“/blog/show/this-is-my-blog”,但您没有指定您浏览到的 URI 是什么,也没有指定是否传递 $ show() 函数的 blog 参数。
标签: php codeigniter url-rewriting