CodeIgniter学习笔记(十一)——CI中的URL

当PHP程序部署在服务器上时,用户会将程序安装到指定目录,程序员无法预先知道用户会安装到哪个目录,因此对于代码中出现的URL不能写死,需要通过URL辅助函数动态获取,在使用函数前需要先加载URL辅助函数库($this->load->helper('url'))或配置/application/config/autoload.php自动加载。

site_url():返回以config.php中指定的base_url和index.php,还有传递给函数的URL段参数拼接成的字符串

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form action=<?php echo site_url('user/index4'); ?> method="post">
        name:<input type="text" name="name" /><br />
        password:<input type="text" name="password"><br />
        <input type="submit" name="submit" value="submit" />
    </form>
</body>
</html>

base_url():返回项目的基础目录

<img src="<?php echo base_url(); ?>upload/qe.jpg">
current_url():返回当前查看页面的完整URL
原文地址:https://www.cnblogs.com/iamsupercola/p/4635720.html