The third day thinkphp hand high-speed splicing site (iii)

Source: Internet
Author: User

June 1, light rain. "Plum yellow apricot fat, wheat flower snow cabbage flower sparse."

Day long Fence No one, only dragonfly Vanessa Butterfly fly. ”

vii.MVC pattern

        thinkphp MVC Development Mechanisms such as the following:

M model Layer Models : is the database Operation class (through the database operation class to manipulate each table).
V View Layer view: refers to the template.


C Controller Layer controllers: It is through the controller to achieve the template, the control relationship between the model.

in an MVC architecture, a controller is required. Because the controller governs the control of the business logic .

The usual process is that the request is entered from the portal file. Then the route is matched. Finally, the control is handed over to the corresponding controller. Start processing business, model and view calls are determined by the controller's code. In other words, the ability to use the model and VIew in a controller simply means that your business does not interact with the database (model) and does not produce any expressive output (View).

       Eight, background writing

< Span style= "font-family:"microsoft yahei"; Color: #993399 ">        1, change admin/lib/action/indexaction.class.php. For example, the following:

<?php//This class is generated by the system on its own initiative, for testing purposes class Indexaction extends Action {public Function index () {if (Session ('? Username ')) {} el SE {$this->error (' Pro, Hello, please login first! ', U ('/login/index/'));}}}

Code Description:

To infer whether a session value has been set, you can use the session ('? name '); Used to infer whether the SESSION value named name has been set equal to: Isset ($_session[' name ');

the meaning of U ('/login/index/') is to find the index method under the Login module .


2, write admin\lib\action\loginaction.class.php

<?

Phpclass Loginaction extends Action {function index () {//config page display content $this->assign (' title ', ' admin system '); $this->displa Y ();}}

Use the Assign method in action to assign a value to a template variable . using the built-in template engine output variables, you only need to use: {$title} in the stencil file. After the template compiles the result is <

PHP echo ($title);

At the end of the execution, the output of the thinkphp can be displayed in the label position.
Note that the template label cannot have spaces between {and $ no matter what. Otherwise the label is invalid.

3, write admin\tpl\login\index.html

Directly to the background template, Admin-templates.rar inside the login.html inside all the contents of the copy into.

front and back table template: http://download.csdn.net/detail/zwszws/8773601

put the downloaded front-end template inside the directory Css, Images and scripts inside the file all into Public\css\admin and \public\images\admin and \publicjs\ Admin inside.

change the associated resource path in the index.html file. such as:

<link rel= "stylesheet" href= "__public__/css/admin/reset.css"

<script type= "Text/javascript" src= "__public__/js/admin/jquery-1.3.2.min.js" ></script>



4. Revisit the question: http://localhost/MyFirstThinkPHP_1/admin.php. Oh, the background login page came out.


5, add a verification code

Change the admin\tpl\login\index.html file. Increase

<p>        <label> Verification Code </label>        <input class= "Text-input" type= "text" name= "verify"/>         </p>    <script>function Show (obj) { Obj.src= "__app__/common/verify";} </script>
Writing admin\lib\action\commonaction.class.php

<?

Phpclass Commonaction extends action{function Verify () {//import the Captcha class import ("ORG. Util.image "); */* 1: Verification code Length, default 4 * Parameter 2: type. 0 is a letter. 1 is a number. 2 is uppercase. 3 is a lowercase letter. 4 for Chinese * 3: Picture type, default PNG format, if the server does not open PNG, change to another format * 4: Image width (based on the length of their own initiative) * Reference 5: Image height, default 22 pixels * Reference 6: Verification code saved in Session name ' verify ' */image::buildimageverify (4,1, ' png ', 70,30);//Static Method}}?

>

4. Revisit the question: http://localhost/MyFirstThinkPHP_1/admin.php. Oh. The verification code is out!





The third day thinkphp hand high-speed splicing site (iii)

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.