How to write php entry file

爱喝马黛茶的安东尼
Release: 2023-02-25 14:14:02
Original
4209 people have browsed it

How to write php entry file

First, let’s understand the running process of the framework:

Entry file-> Define constants-> Introduce function library-> Automatically load classes-> Start Framework-> Route Analysis-> Loading Controller-> Return Result

How to write php entry file

##Related recommendations: "

php Getting Started Tutorial"

Entry file index.php:

<?php
/*
入口文件
1.定义常量
2.加载函数库
3.启动框架
*/
// 定义当前框架所在的根目录
define(&#39;IMOOC&#39;, __DIR__);
// 定义框架核心文件所在的目录
define(&#39;CORE&#39;, IMOOC.&#39;/core&#39;);
// 项目文件所在目录
define(&#39;APP&#39;, IMOOC.&#39;/app&#39;);
// 定义项目调试模式
define(&#39;DEBUG&#39;, true);
// 判断项目是否处于调试状态
if (DEBUG) {
    // 设置报错级别:显示所有错误
    ini_set(&#39;display_error&#39;, &#39;On&#39;);
}else{
    ini_set(&#39;display_error&#39;,&#39;Off&#39;);
}
// 加载函数库
include CORE.&#39;/common/function.php&#39;;
// 加载框架核心文件
include CORE.&#39;/imooc.php&#39;;
\core\Imooc::run();
Copy after login

Public function function.php in the framework core directory:

<?php
/*
输出对应的变量或者数组
*/
function p($var){
    if(is_bool($var)){
        var_dump($var);
    }elseif (is_null($var)) {
        var_dump(NULL);
    }else{
        echo &#39;<pre style="position:relative;z-index:1000;padding:10px;border-radius:5px;background:#f5f5f5;
        border:1px solid #aaa;font-size:14px;line-height:18px;opacity:0.9;">&#39;.print_r($var,true).&#39;
Copy after login
'; } }

Framework core file imooc.php:

<?php
namespace core;
class Imooc
{
    static public function run()
    {
        p(&#39;ok&#39;);
    }
}
Copy after login

Run the project, After accessing the entry file index.php, the browser outputs: ok as expected.

The above is the detailed content of How to write php entry file. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!