zoukankan      html  css  js  c++  java
  • CodeIgniter学习笔记四:CI中的URL相关函数,路由,伪静态,去掉index.php

    一、URL相关函数

    1、加载url模块

    加载url有两种方式:

    a、自动加载:在 application/config/autoload.php 中开启 

    $autoload['helper'] = array('url');

    b、手动加载:

    $this -> load -> helper('url');

    2、site_url("controller/action")

    用于生成完整地址,可用于form的action属性中。

    3、base_url

    获得网站根目录,是浏览地址(不是物理地址)

    示例:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Url Test</title>
    </head>
    <body>
        <form action="<?php echo site_url('urltest/add'); ?>" method="post">
            <input type="submit" value="Add"/>
        </form>
        <img src="<?php echo base_url(); ?>uploads/1.jpg" alt="" />
    </body>""
    </html>

    二、路由

    1、配置文件在application/config/routes.php

    2、默认控制器:

    $route['default_controller'] = 'welcome';

    三、伪静态(自定义后缀)

    //正则路由
    $route['news/([d]+).html'] = 'article/show/$1';
    $route['article/show/([d]+).html'] = 'article/show/$1';

    四、去掉index.php

    根据不同Web服务器,添加配置。

    如果web服务器是apache,先开启rewrite模块,重启apache,然后在网站根目录(入口文件同级)中添加.htaccess文件:

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </IfModule>

    即可

  • 相关阅读:
    1.2c#变量和运算符及注释
    1.1c#初识
    约数个数定理
    莫比乌斯反演
    欧几里得/拓展欧几里得
    中国剩余定理【数论】
    欧拉定理/欧拉函数【数论】
    费马小定理【数论】
    同余定理【数论】
    Java class 和public class 区别
  • 原文地址:https://www.cnblogs.com/lurenjiashuo/p/ci-note-basic-4-url-route-remove-index-php.html
Copyright © 2011-2022 走看看