Home >Backend Development >PHP Tutorial >PHP framework - Which file in thinkPHP defines global predefined constants that can be called in all controllers and models in the future?

PHP framework - Which file in thinkPHP defines global predefined constants that can be called in all controllers and models in the future?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-12-01 01:27:201486browse

That is, I want to define some global constants,

For example, the stand-alone path of a certain file, api interface, etc., in the future I can just call this constant directly in the controller and model class files...

Excuse me, which file should I write the constants in?

Reply content:

That is, I want to define some global constants,

For example, the stand-alone path of a certain file, api interface, etc., in the future I can just call this constant directly in the controller and model class files...

Excuse me, which file should I write the constants in?

Entry file

Just before Controller is called by ThinkPHP, you can write a const.php to specifically define some constants and import them into the entry file.

index.php

<code>#我喜欢用绝对路径,有时候相对路径嵌套require可能会引起一些错误。
require APP_PATH.'../config/const.php';</code>

It seems that it can be defined in the entry file

Statement:
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