Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在CodeIgniter中创建类似文章名称的URL?_Php_Codeigniter - Fatal编程技术网

Php 如何在CodeIgniter中创建类似文章名称的URL?

Php 如何在CodeIgniter中创建类似文章名称的URL?,php,codeigniter,Php,Codeigniter,我使用一个函数从数据库中获取文章,该函数在single_view.php中加载文章。url类似于www.example/Blog/function 我想用我的文章名创建我的url,如 www.example.com/Blog/my article name.html 我如何在CodeIgniter中完成它 $route['blog(/:any)*'] = "blog/article" 应用中/圆锥/路线 或 如果您知道要点击哪篇文章,那么每次点击都可以在控制器中创建一个函数,但我相信如果您有

我使用一个函数从数据库中获取文章,该函数在
single_view.php
中加载文章。url类似于
www.example/Blog/function

我想用我的文章名创建我的url,如
www.example.com/Blog/my article name.html

我如何在CodeIgniter中完成它

$route['blog(/:any)*'] = "blog/article" 
应用中/圆锥/路线


如果您知道要点击哪篇文章,那么每次点击都可以在控制器中创建一个函数,但我相信如果您有很多文章,那么代码大小会增加,所以选择路由解决方案。

您是否设置了路由来处理此问题?按照
$route['blog(/:any)*']=“blog/article”的思路如何使用它。你可以在你的路线中使用@KaiQing共享的代码。你可以从阅读CodeIgniter文档和文档中包含的简易教程开始。说真的,这是我很久以来看到的最懒的问题之一。在/application/config/routes.php中,您应该阅读routes。我的示例意味着有一个blog控制器和一个article方法。此外,您应该为文章ID使用一个uri段,因为让它单独处理slug可能是有害的。