zoukankan      html  css  js  c++  java
  • 8.2 tp5 入口文件和路由

    1、入口文件访问优化

    1) 在public文件夹下建立 admin.php文件

    2) 打开admin.php文件,复制

        // 定义应用目录

    define('APP_PATH', __DIR__ . '/../application/');

    // 加载框架引导文件

    require __DIR__ . '/../thinkphp/start.php';

    3) 分别在两个入口文件中绑定模块

    Public/index.php => define('BIND_MODULE', 'index'); 

    Public/admin.php => define('BIND_MODULE','admin' );

         之前的访问

          Index.php/index/Index/index   admin.php/admin/Index/index

         修改后的访问(省略了模块项)

          Index.php/Index/index         admin.php/Index/index

          入口文件   控制器  方法  

    4)隐藏入口文件

       Apache的配置过程,可以参考下:
          a、httpd.conf配置文件中加载了mod_rewrite.so模块

          b、AllowOverride None None改为 All  在虚拟主机中把这一项改为All
          c、在应用入口文件同级目录添加.htaccess文件,内容如下:

    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]  其中的index.php就是入口文件,     如果隐藏后台的入口文件  则改成admin.php

    5 设置路由  动态单个注册(TP5 hinkphplibrary hinkRoute.php)中的rule()方法

    ====================index.php==========================

    <?php
    // +----------------------------------------------------------------------
    // | ThinkPHP [ WE CAN DO IT JUST THINK ]
    // +----------------------------------------------------------------------
    // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
    // +----------------------------------------------------------------------
    // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
    // +----------------------------------------------------------------------
    // | Author: liu21st <liu21st@gmail.com>
    // +----------------------------------------------------------------------
    
    // [ 应用入口文件 ]
    
    // 定义应用目录
    define('APP_PATH', __DIR__ . '/../application/');
    define('BIND_MODULE', 'index'); 
    // 加载框架引导文件
    require __DIR__ . '/../thinkphp/start.php';

    =========================admin.php===========================

    <?php
    // +----------------------------------------------------------------------
    // | ThinkPHP [ WE CAN DO IT JUST THINK ]
    // +----------------------------------------------------------------------
    // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
    // +----------------------------------------------------------------------
    // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
    // +----------------------------------------------------------------------
    // | Author: liu21st <liu21st@gmail.com>
    // +----------------------------------------------------------------------
    
    // [ 应用入口文件 ]
    
    // 定义应用目录
    define('APP_PATH', __DIR__ . '/../application/');
    define('BIND_MODULE','admin' );
    // 加载框架引导文件
    require __DIR__ . '/../thinkphp/start.php';

    ================.htaccess文件================

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

    ================route.php=======================

    <?php
    // +----------------------------------------------------------------------
    // | ThinkPHP [ WE CAN DO IT JUST THINK ]
    // +----------------------------------------------------------------------
    // | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
    // +----------------------------------------------------------------------
    // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
    // +----------------------------------------------------------------------
    // | Author: liu21st <liu21st@gmail.com>
    // +----------------------------------------------------------------------
    
    /*return [
        '__pattern__' => [
            'name' => 'w+',
        ],
        '[hello]'     => [
            ':id'   => ['index/hello', ['method' => 'get'], ['id' => 'd+']],
            ':name' => ['index/hello', ['method' => 'post']],
        ],
    
    ];*/
    use thinkRoute;
    //Route ::rule('index','index/index');
    Route ::rule('test','Index1/test');
    Route ::rule('get','Index1/getFunc');
  • 相关阅读:
    搜索型SQL注入解决方法
    windows10系统下phpstudy安装php8版本
    齐博cms基础教程之认识齐博cms
    thinkphp查找父级栏目及子级栏目的所有文章
    phpstudy+iis搭建php项目
    python办公自动化基础搜索文件
    thinkphp屏蔽ip访问项目做法
    thinkphp使用paypal进行支付的做法详细步骤
    数据库无法插入数据解决方法
    tp5发送邮件适用于常用的php版本做法
  • 原文地址:https://www.cnblogs.com/sunhao1987/p/9410282.html
Copyright © 2011-2022 走看看