How would you reference this object with a URL, with a meaningful name? You could use Article.id so the URL would look like this:

www.example.com/article/23

Or, you could reference the title like so:

www.example.com/article/The 46 Year Old Virgin

Problem is, spaces aren't valid in URLs, they need to be replaced by %20 which is ugly, making it the following:

www.example.com/article/The%2046%20Year%20Old%20Virgin

That's not solving our meaningful URL. Wouldn't this be better:

www.example.com/article/the-46-year-old-virgin

That's a slug. the-46-year-old-virgin. All letters are downcased and spaces are replaced by hyphens -. See the URL of this very webpage for an example!

 $slug = url_title($this->input->post('title'), 'dash', TRUE);

用于将字符串 中的所有空格替换成连接符(-),并将所有字符转换为小写。 这样其实就生成了一个 slug ,可以很好的用于创建 URI 。

http://stackoverflow.com/questions/427102/what-is-a-slug-in-django

http://www.sjyhome.com/wordpress/wp-slug.html

最新文章

  1. 如何把Power BI嵌入到Web应用中
  2. Android开发之ProgressDialog与ProgressBar
  3. React Native Tips
  4. Qt 中QString 字符串操作:连接、组合、替换、去掉空白字符
  5. 操作系统之cache、伙伴系统、内存碎片、段式页式存储管理
  6. kvm 客户机加载移动硬盘
  7. C++11常用特性的使用经验总结
  8. BZOJ5063旅游——非旋转treap
  9. js 或 且 非
  10. windows上使用logstash-input-jdbc
  11. java分层
  12. 「ZJOI 2010」 排列计数
  13. R Language Learn Notes
  14. php now 5.2 升级5.3
  15. PPTP vs. OpenVPN vs. L2TP/IPsec vs. SSTP
  16. 基于LSB的图像数字水印实验
  17. Dubbo超时机制导致的雪崩连接
  18. [转]git merge 跟 git merge -no-ff
  19. Centos7安装遇到的问题及详解
  20. swift Equatable 函数签名的测试

热门文章

  1. cordova 安卓项目打包 release安装包
  2. 1-9方法的重写(override)
  3. C语言精确微秒级的延时
  4. #219. 【NOI2016】优秀的拆分
  5. 【转】Java泛型方法
  6. SQL异常为"当IDENTITY_INSERT设置为OFF时" 的解决
  7. (译文)IOS block编程指南 3 概念总览
  8. (转)使用JDK中的Proxy技术实现AOP功能
  9. EXPLAIN - 显示语句执行规划
  10. Django 路由 —— Djangon如何处理一个请求