SpeedPHP framework learning-1. basic and MVC understanding SpeedPHP is a PHP framework based on quick learning. Its architecture is simple and the learning curve is concise. Here, a CMS system is used as an example to record the process of using SP. Download the SP compressed package, decompress it to the root directory of the server, and access the server. The files in the SP directory have the controll SpeedPHP framework learning-1. basic and MVC understanding.
SpeedPHP is a PHP framework based on quick learning. it has a simple architecture and a simple learning curve. Here, a CMS system is used as an example to record the process of using SP.
Download the SP compressed package, decompress it to the root directory of the server, and access the server. The files in the SP directory include the controller, model, SpeedPHP, and tmp directories. the SpeedPHP file is the system file, and the Controller file is the controller file. The program starts from index. php.
array( 'host' =>'localhost', 'login' =>'root', 'password' =>'root', 'database' =>'test', ), 'view' => array( 'enabled' =>TRUE, 'config'=>array( 'template_dir'=> APP_PATH.'/tpl', 'compile_dir'=> APP_PATH.'/tmp', 'cache_dir'=> APP_PATH.'/tmp', 'left_delimiter'=> '<{', 'right_delimiter'=> '}>', ), ));require(SP_PATH."/SpeedPHP.php");spRun();
The above program defines the path of the App and SP, loads the configuration of the database and view layer, loads the core library file of the SP, and finally runs the entire system. When the above program runs, the index method under the main class is first executed under the Controller directory. The main class program is as follows:
spArgs("tpl","green"); $guestbook =spClass("guestbook"); $this->results= $guestbook->findAll(); $this->display("{$tpl}/index.html"); } function write(){ $guestbook =spClass("guestbook"); $newrow =array( 'name'=> $this->spArgs('name'), 'title'=> $this->spArgs('title'), 'contents'=> $this->spArgs('contents'), ); $guestbook->create($newrow); echo "return"; }}
From index. php, the index function of the main method is called by default. In this example, this function first sets the template name parameter (tpl ). Create another model. Use the findall method of the model to find all database information. Finally, use the tpl Template to display the results. The controller program must inherit from the spController class. the method name is the called action name. When explicitly calling a program, the path is index. php? C = main & a = write. The Model is a class file with the same name as the database table. This model must inherit from the spModel and have the primary key and table name attributes set.
Use the following program in the index.html file in the tpltemplate.txt file to format the output result.
<{foreach from=$results item=one}> <{$one.title}> <{$one.name}>:
<{$one.contents}>
<{/foreach}>From the MVC perspective, the class in the model is equivalent to the model. it corresponds to every table in the database and is operated in the controller. The html file is equivalent to the view layer. in the SP architecture, the file in the TPL file directory is displayed, and operations such as program calling are completed in the Controller layer. The control layer corresponds to class files in the Controller directory and is the core of the program.