SpeedPHP framework learning-1. basic and MVC knowledge

Source: Internet
Author: User
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.

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.