Judging teacher PHP Devil Special Training Note (8)

Source: Internet
Author: User
Tags echo date

To create a template file:

The teacher led us to start creating the template, according to the teacher's guidance, we hope that a code is written: 1, for example, I define a variable $name= '; 2, and then I read a template. 3, and then I set up in this template some of their own "display format" (Force lattice). 4, after loading the template can be directly replaced with the above variables.

First, create a new index.tpl in the template folder. The content is so written

Echo ' <?php '?>  /* * * * Project name: <?php echo $prj _name?>  //Everyone think, can it run? *user: <?php echo $prj _author?>    //Can I run it? *date: <?php echo Date (' y-m-d ')?>  //can ? */    Echo "Hello ShenYi";? >

  Well, the prep work is done, and we're referencing it in the God_frame class:

<?phpnamespace Core\frame;classgod_frame{ Public  $project _folder= ";//project Folder     Public  $project _main= ";//Entry File    function__construct ($prjName){//constructor Function       $this->project_folder =GETCWD()." /".$prjName; $this->project_main =$thisProject_folder. " /index.php "; }    functionrun () {//determine and generate a new folder, without creating!file_exists($this->project_folder) &&mkdir($this-Project_folder); Gets the external member variable and returns the array of the function to the variable listExtract(Get_object_vars($this)); Open the internal buffer (memory) of PHPOb_start(); //Introducing Template Paths        include(dirname(__file__).‘ /template/index.tpl '); //gets the contents of the buffer and assigns it to the $cnt        $cnt=ob_get_contents(); //Cleanup Buffer Contents        Ob_end_clean(); //generate a index.php file under this folder without creating and overwriting        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 $get _config-prj_name;         $GF $get _config-prj_author;         $GF  Run ();    }

Execute this method on the command line

  

Then we look at the directory structure of the entire document and the contents of the index.php

   

The point of knowledge of evil:

__FILE__:

DirName ():

Ob_start (): Open the internal buffer (memory) of PHP. Put the contents of the next display in the buffer, not to panic in the display.
Ob_get_contents (); function to get the contents of the buffer
Ob_end_clean (); The buffer contents can be cleared so that no content is output
Ob_end_flush (); Closes the buffer and outputs the contents
Get_object_vars (); You can get the value of the property variable in the class (the class being instantiated) and return the array.

Extract ();

Copyright Notice: NOTE-taker fugitive pawns love freedom, advocating sharing. But this note stems from www.jtthink.com (programmer in the awkward way) judging teacher's "PHP Devil training First stage." This study note pawn in the blog Park debut, if need to reprint please respect the teacher Labor, retain judging teacher attribution and course source address.

Previous lesson: judging teacher PHP Devil Special Training Note (7)--What's my name?

Judging teacher PHP Devil Special Training Note (8)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.