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

WBOY
Release: 2023-03-02 10:12:02
Original
1434 people have browsed it

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>
Copy after login

It seems that it can be defined in the entry file

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template