01. PHP的CI4框架自带了很多好用的URL辅助函数,我选择了以下这些比较常用的列了出来,代码如下:
<?php namespace AppControllers; // http://127.0.0.1/CI4/public/index.php/hello/ class Hello extends BaseController { public function index() { //http://localhost/CI4/index.php/news/local/123 0 echo site_url('news/local/123') . ' 0<br>'; //http://localhost/CI4/index.php/news/local/123 1 $segments = array('news', 'local', '123'); echo site_url($segments) . ' 1<br>'; //http://localhost/CI4 2 echo base_url() . ' 2<br>'; //http://localhost/CI4/blog/post/123 3 echo base_url("blog/post/123") . ' 3<br>'; //http://localhost/CI4/images/icons/edit.png 4 echo base_url("images/icons/edit.png") . ' 4<br>'; //hello 5 echo uri_string() . ' 5<br>'; //http://localhost/CI4/hello 6 echo base_url(uri_string()) . ' 6<br>'; //hello 7 echo uri_string('http://some-site.com/blog/comments/123') . ' 7<br>'; //index.php 8 echo index_page() . ' 8<br>'; //My News 9 echo anchor('news/local/123', 'My News', 'title="News title"') . ' 9<br>'; //My News 10 echo anchor('news/local/123', 'My News', array('title' => 'The best news!')) . ' 10<br>'; //Click here 11 echo anchor('', 'Click here') . ' 11<br>'; } }
02.效果如下
原创不易,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢。