speedphp Framework Learning-1. Basic and MVC know

Source: Internet
Author: User
Tags php framework
speedphp Framework Learning-1. Basic and MVC Understanding

Speedphp is a fast learning-based PHP framework, its architecture is simple, learning curve is more concise. Here, for example, a CMS system is used to record the process of using SP.

Download the SP compression package, unzip it in the root directory of the server and access the server. The files in the SP directory have controller, model, speedphp, and TMP directories, where speedphp is the system file and controller file. 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 ' and 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 layers, loads the SP's core library files, and finally runs the entire system. When the above program runs, the index method under the main class is executed first to the controller directory. The program for the main class 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 case the function first sets the template name parameter (TPL). Then create a new model. Use the model's FindAll method to find all database information. Finally, the result is displayed using the TPL template. The above controller program, must inherit from the Spcontroller class, the method name is called the action name. The path is index.php?c=main&a=write when explicitly called in the program. The model is shown below, which is a class file with the same name as the database table. This model must inherit from Spmodel, with both the primary key and the table Name property set.

 
  

Use the following program in the index.html file in the TPL template directory to format the output.

<{foreach from= $results item=one}>     

<{$one .title}>

<{$one. Name}>:
<{$one .contents}>

<{/foreach}>
From the MVC point of view, the class in model, which corresponds to each table in the database, is manipulated in the controller. And the HTML file is equivalent to the view layer, in the SP schema to ask the TPL file directory files, his program calls and other operations in the controller layer is completed. The control layer corresponds to the class file in the controller directory, which 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.