国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home 類庫下載 PHP類庫 PHP devil training

PHP devil training

Oct 10, 2016 am 11:13 AM

In this class, the teacher led us to create TEMPLATE. According to the teacher's teaching, we hope to write the code in this way: 1. For example, I define a variable $name=‘’; 2. Then I read a template. 3. Then I set some of my own "display formats" (hard style) in this template. 4. After loading the template, you can directly replace it with the above variables.

1. First create a new index.tpl in the template folder. The content is written like this

<?php echo &#39;<?php&#39; ?>  
/**
* project name: <?php echo $prj_name ?>  //大家想想, 它能運行嗎?
*User: <?php echo $prj_author ?>    //能運行嗎?
*Date: <?php echo date(&#39;Y-m-d&#39;)?>  //能嗎?
*/

    echo "hello shenyi";
?>

Okay, the preparations are done, we reference it in the god_frame class:

<?php
namespace core\frame;

class god_frame
{
    public  $project_folder = &#39;&#39;;       //項目文件夾
    public  $project_main = &#39;&#39;;         //入口文件
    function __construct($prjName){      //構(gòu)造函數(shù)
       $this->project_folder = getcwd()."/".$prjName;
       $this->project_main = $this ->  project_folder."/index.php";
    }
    function run(){

        //判斷并生成新的文件夾,沒有就創(chuàng)建
        !file_exists($this->project_folder) && mkdir($this->project_folder);
     //獲取外部成員變量并把該函數(shù)獲取的數(shù)組返回成變量列表 
        extract(get_object_vars($this));
        開啟PHP的內(nèi)部緩沖區(qū)(內(nèi)存)
        ob_start();
        //引入模板路徑
        include (dirname(__FILE__).&#39;/template/index.tpl&#39;);
        //獲取緩沖區(qū)的內(nèi)容,并賦給$cnt
        $cnt =ob_get_contents();
        //清理緩沖區(qū)內(nèi)容
        ob_end_clean();

        //在該文件夾下生成一個index.php文件,沒有就創(chuàng)建并覆蓋
        file_put_contents($this->project_main,"$cnt");
    }   
}
?>

I also need to improve the start (method) in godinit

static function start(){
        $get_config = loadConfig();
        $gf = new god_frame($get_config->prj_name);
        $gf -> prj_name = $get_config->prj_name;
        $gf -> prj_author = $get_config->prj_author;
        $gf -> run();
    }

Execute this method in the command line

PHP devil training

Then let’s take a look at the directory structure of the entire document and the contents of index.php

PHP devil training

Added knowledge points:

__FILE__:

dirname():

ob_start(): Start PHP internal buffer (memory). Put the content to be displayed next into the buffer first, and display it without haste.
ob_get_contents(); function to get the contents of the buffer
ob_end_clean(); You can clear the buffer contents, so that Output content
ob_end_flush(); Close the buffer and output the content
get_object_vars(); You can get the attribute variable values ????in the class (the instantiated class) and return the array.

extract();


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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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)

Hot Topics

PHP Tutorial
1500
86