Do you think the thinkphp framework is good? Laravel is elegant? Is Yii stable? Is CI very efficient? Hum, in fact, your own development is the best use of the most suitable for your framework!
Course Play Address: http://www.php.cn/course/276.html
The teacher's lecture style:
The lectures are kind and natural, unpretentious, no affectation, nor deliberately rendered, but instilled, careful way, between teachers and students in a kind of equality, cooperation, harmonious atmosphere, the silent emotional exchange, the thirst for knowledge and exploration into a simple, real teaching situation, students in the quiet thinking, To gain knowledge in silent consent
The difficulty in this video is to configure the load class (1):
First, configure the load class
To do the configuration load class we need to understand why we need to use the collocation load class
When we need to change a certain configuration of the time we do not need to find all the configuration in the function to modify, but directly in a separate configuration file modification, so as to better optimize our framework, it will be more comfortable to use.
For example, our database configuration
We can make a separate database configuration file into the config file.
<?php return Array ( ' DSN ' = ' mysql:host=localhost;dbname=test ', ' USERNAME ' = ' root ', ' PASSWD ' = ' root ' ) ?>
Next let's load the configuration file
Public Function __construct () { $database = conf::all (' database '); try { parent::__construct ($database [' DSN '], $database [' USERNAME '], $database [' PASSWD ']); } catch (\ Pdoexception $e) { p ($e->getmessage ()); } }
In this case, we just need to modify the configuration file to modify our database connection is not very convenient
Second, the Log class
The log class is an essential feature in all frameworks, and the log class may exist in the database or exist in the file.
Create a log in the config file. PHP configuration file, where the file storage and storage path
<?php return Array ( ' drive ' = ' file ', ' OPTION ' = = Array (' PATH ' = ' = ' lhy '). /log/' ) ); ? >
Create a log file in the Lib file, and then create a file.php file from the log file, which is implemented in the file.php file to deposit the log in the file
<?php namespace Core\lib\drive\log; Use core\lib\conf; class file {public $path; #日志存储路径 public function __construct () { $conf = conf::get (' OPTION ', ' log '); $this->path = $conf [' path ']; } Public function log ($message, $file) { $path = $this->path; echo $this->path.date (' y-m-d ');d ie; if (!is_dir ($this->path.date (' y-m-d '))) { mkdir ($this->path.date (' y-m-d '), 0777,true); } $message = Date (' y-m-d h:i:s '). $message; Return file_put_contents ($this->path.date (' y-m-d '). ' /'. $file. '. PHP ', Json_encode ($message). php_eol,file_append); } } ? >
To create a log.php class file in a Lib file
<?php namespace Core\lib; Use core\lib\conf; Class Log {static $class; /** * 1. Determine how the log is stored * * 2. Write log */static public function init () {//determine storage mode $drive = Conf::get (' Drive ', ' log '); $class = ' \core\lib\drive\log\\ '. $drive; Self:: $class = new $class; } static Public Function log ($message, $file) {//core\lib\drive\log\log; Self:: $class->log ($message, $file); }};