Home Backend Development PHP Tutorial thinkphp3.2中Lite文件替换框架入口文件或应用入口文件的方法_php实例

thinkphp3.2中Lite文件替换框架入口文件或应用入口文件的方法_php实例

May 16, 2016 pm 08:15 PM
thinkphp3.2 replace

本文实例讲述了thinkphp3.2中Lite文件替换框架入口文件或应用入口文件的方法。分享给大家供大家参考。具体分析如下:

3.2版本支持根据当前的运行环境生成Lite文件,可以替换框架的入口文件或者应用入口文件,提高运行效率。

我们的建议是在生产环境中关闭调试模式后生成Lite文件。

注意,目前SAE平台不支持直接生成Lite文件。

生成Lite文件

要生成Lite文件,需要在入口文件中增加常量定义:

复制代码 代码如下:
define('BUILD_LITE_FILE',true);

默认情况下,再次运行后会在Runtime目录下面生成一个lite.php文件。

如果你需要修改Lite文件的位置或者名称,可以在应用配置文件中增加配置如下:

复制代码 代码如下:
'RUNTIME_LITE_FILE'=> APP_PATH.'lite.php'

配置后,生成的Lite文件的位置为 APP_PATH.'lite.php'。

Lite文件的编译文件内容是系统默认的,如果希望改变或者增加其他的编译文件的话,可以在外部定义编译列表文件,例如: 我们在应用配置目录下面增加lite.php定义如下:

return array(
  THINK_PATH.'Common/functions.php',
  COMMON_PATH.'Common/function.php',
  CORE_PATH . 'Think'.EXT,
  CORE_PATH . 'Hook'.EXT,
  CORE_PATH . 'App'.EXT,
  CORE_PATH . 'Dispatcher'.EXT,
  CORE_PATH . 'Model'.EXT,
  CORE_PATH . 'Log'.EXT,
  CORE_PATH . 'Log/Driver/File'.EXT,
  CORE_PATH . 'Route'.EXT,
  CORE_PATH . 'Controller'.EXT,
  CORE_PATH . 'View'.EXT,
  CORE_PATH . 'Storage'.EXT,
  CORE_PATH . 'Storage/Driver/File'.EXT,
  CORE_PATH . 'Exception'.EXT,
  BEHAVIOR_PATH . 'ParseTemplateBehavior'.EXT,
  BEHAVIOR_PATH . 'ContentReplaceBehavior'.EXT,
);

Copy after login

所有在lite.php文件中定义的文件都会纳入Lite文件的编译缓存中。你还可以对生成的lite文件进行修改。

如果你修改了框架文件和应用函数和配置文件的话,需要删除Lite文件重新生成。

由于SAE等云平台不支持文件写入,因此不支持直接生成Lite文件。

替换入口

Lite文件可以用于替换框架入口文件或者应用入口文件。

替换框架入口文件

Lite文件生成后,就可以把原来的应用入口文件中的框架入口文件修改如下:

复制代码 代码如下:
require './ThinkPHP/ThinkPHP.php';

改成:
复制代码 代码如下:
require './Runtime/lite.php';

替换Lite文件后,应用编译缓存不再需要。

替换应用入口文件

如果你的入口文件没有其他代码和逻辑的话,还可以直接把lite.php文件作为应用的入口文件访问。 把lite.php 文件复制到应用入口文件的相同目录,并直接改名为index.php即可和原来一样正常访问(原来的应用入口文件可以备份以备用于重新生成Lite文件的时候使用)。

注意:如果你的环境或者目录位置发生变化,以及更改了核心框架和应用函数、配置等文件后,则需要重新生成Lite文件。

希望本文所述对大家的基于ThinkPHP框架的php程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Master PyCharm replacement shortcut keys in 5 minutes and easily increase your programming speed! Master PyCharm replacement shortcut keys in 5 minutes and easily increase your programming speed! Feb 22, 2024 am 10:57 AM

PyCharm is a commonly used Python integrated development environment with rich functions and shortcut keys that can help developers improve programming efficiency. In the daily programming process, mastering PyCharm's shortcut key replacement skills can help developers complete tasks more quickly. This article will introduce you to some commonly used replacement shortcut keys in PyCharm to help you easily improve your programming speed. 1.Ctrl+R replacement In PyCharm, you can use the Ctrl+R shortcut key to perform replacement operations.

PyCharm Beginner's Guide: Comprehensive Analysis of Replacement Functions PyCharm Beginner's Guide: Comprehensive Analysis of Replacement Functions Feb 25, 2024 am 11:15 AM

PyCharm is a powerful Python integrated development environment with rich functions and tools that can greatly improve development efficiency. Among them, the replacement function is one of the functions frequently used in the development process, which can help developers quickly modify the code and improve the code quality. This article will introduce PyCharm's replacement function in detail, combined with specific code examples, to help novices better master and use this function. Introduction to the replacement function PyCharm's replacement function can help developers quickly replace specified text in the code

Replace the class name of an element using jQuery Replace the class name of an element using jQuery Feb 24, 2024 pm 11:03 PM

jQuery is a classic JavaScript library that is widely used in web development. It simplifies operations such as handling events, manipulating DOM elements, and performing animations on web pages. When using jQuery, you often encounter situations where you need to replace the class name of an element. This article will introduce some practical methods and specific code examples. 1. Use the removeClass() and addClass() methods jQuery provides the removeClass() method for deletion

Use java's StringBuilder.replace() function to replace a specified range of characters Use java's StringBuilder.replace() function to replace a specified range of characters Jul 24, 2023 pm 06:12 PM

Use java's StringBuilder.replace() function to replace a specified range of characters. In Java, the StringBuilder class provides the replace() method, which can be used to replace a specified range of characters in a string. The syntax of this method is as follows: publicStringBuilderreplace(intstart,intend,Stringstr) The above method is used to replace the index star from

How to use the REPLACE function to replace a specified part of a string in MySQL How to use the REPLACE function to replace a specified part of a string in MySQL Jul 25, 2023 pm 01:18 PM

MySQL is a commonly used relational database management system that provides a variety of functions to process and operate data. Among them, the REPLACE function is used to replace the specified part of the string. In this article, we will introduce how to use the REPLACE function for string replacement in MySQL and demonstrate its usage through code examples. First, let’s take a look at the syntax of the REPLACE function: REPLACE(str,search_str,replace_str).

How to replace a word in Excel using Python? How to replace a word in Excel using Python? Sep 16, 2023 pm 10:21 PM

In Python, we can replace one word with another word in Excel using a third-party Python library called openpyxl. Microsoft Excel is a useful tool for managing and analyzing data. Using Python, we can automate some Excel data management tasks. In this article, we will learn how to replace a word in Excel using Python. Before installing openpyxl to replace Word in Excel, we need to install the openpyxl library in the system using the Python package manager. To install openpyxl, enter the following command in the terminal or command prompt. Pipinst

PyCharm replaces shortcut keys to make programming more convenient! PyCharm replaces shortcut keys to make programming more convenient! Feb 21, 2024 pm 12:03 PM

PyCharm is an integrated development environment popular among programmers. It provides powerful functions and tools to make programming more efficient and convenient. In PyCharm, reasonable setting and replacement of shortcut keys is one of the keys to improving programming efficiency. This article will introduce how to replace shortcut keys in PyCharm to make programming more convenient. 1. Why should we replace shortcut keys? In PyCharm, shortcut keys can help programmers quickly complete various operations and improve programming efficiency. However, everyone has different habits, and some people may

Revealing the secret of how to quickly replace code in PyCharm Revealing the secret of how to quickly replace code in PyCharm Feb 25, 2024 pm 11:21 PM

PyCharm is a Python integrated development environment that is widely loved by developers. It provides many methods to quickly replace code, making the development process more efficient. This article will reveal several commonly used methods to quickly replace code in PyCharm, and provide specific code examples to help developers make better use of these features. 1. Use the replacement function PyCharm provides a powerful replacement function that can help developers quickly replace text in the code. Use the shortcut Ctrl+R or right-click in the editor and select Re

See all articles