first, about JS and CSS path problems1. Find the path is from the portal file index.php to find, rather than from the location of the file itself to find,because we are accessing the portal file when we visit2. Can be placed in the public folder when JS and css are stored3. You can use tags to introduce:3.1 Import Label
The traditional way to import external JS and CSS files is to use the template file directly:
The system provides a special label to simplify the above import:
3.2 Load Tag
Load tag, file mode to import the current project's public JS or CSS
3.3js and CSS Tags
The system also provides two tag aliases for JS and CSS usage and load consistency, for example:
second, third-party class intoThere are two places to put third-party classes .
(1) below the module
(2) New folder or old folder under the library
after you put it in, you need to add a namespace, and the namespace is written from the root namespace
note the rules for naming rules and class names for class filestake pagination as an example:
Originally used the limit tag when paging:
Paging classes can now be introduced as well:
new folder or old folder under the libraryProcedure 1: Create a new Fenye folder under the Thinkphp\library\think folder and copy the previous page.class.php to Fenye
Page.class.php namespace: namespace Think\fenye; (the rest does not change)
Controller inside write: Use think\fenye\page;
ZhuCeController.class.php
1 namespace Home\controller;2 UseThink\controller;3 UseThink\fenye\page;4 classZhucecontrollerextendsController5 {6 7 //third-party class introduction8 functionFenye ()9 {Ten One $model=m ("Nation"); A $total=$model-Count(); - $page=NewPage ($total, 1); - the $sql= "SELECT * From Nation".$page-limit; - $attr=$model->query ($sql); - - $xinxi=$page-fpage (); + //Var_dump ($attr); - $this->assign ("Xinxi",$xinxi); + $this->assign ("Nation",$attr); A at $this-display (); - } -}View Code
View/zhuce/fenye.html:
1<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>5<title> Untitled Document </title>67 8<body>9<table border= "1" width= "40%" >Ten<tr> One<td> Code </td> A<td> name </td> -</tr> -<foreachName= "Nation" item= "V" > the<tr> -<td><{$v.code}></td> -<td><{$v.name}></td> -</tr> +</foreach> -</table> +<div><{$xinxi}></div> A</body> atView Code
Operation Result:
Procedure 2. Practices under the Home module
Create a new folder under Home Fenye then introduce Page.class.php, the rest does not change, the effect is the same
namespace changes within the paging class: namespace Home\fenye
namespace changes inside the controller: use Home\fenye\page
The running result is the same:
Procedure 3. Use home\fenye\page is not used;
Procedure 4: Changing partial conditions of pagination, adding the use of the limit tag
1. Modify the paging class inside the home
2. Modify the wording in the controller
3.Ajax back
(1) URL to become MVC mode, pointing to not the specific page, is the method of operation
(2) When returning a value in the action method, use the Ajaxreturn () method to return, note the return type, the return type is the same as the second parameter
Thinkphp can support AJAX requests very well, and the system's \think\controller class provides the Ajaxreturn method for returning data to the client after an Ajax call. It also supports JSON, JSONP, XML, and eval four ways to accept data to the client, and supports the configuration of data formats returned in other ways.
The data that is returned can support strings, numbers, and arrays, and objects that are returned to the client are encoded and transmitted in different return formats. In the case of the JSON/JSONP format, it is automatically encoded into a JSON string, which, if it is XML, is automatically encoded into an XML string, and if it is eval, only the string data is output.
1) dynamic validation using AJAX returns
1 //Ajax Authentication User name non-null2 functionYhm ()3 {4 $model=d ("Text");5 $rules=Array(6 Array(' uid ', ' require ', ' user name cannot be null '),7 );8 if(!$model->validate ($rules),Create ())9 {Ten $fh=$model-GetError (); One $this->ajaxreturn ($fh, "eval"); A } - Else - { the $fh= "OK"; - $this->ajaxreturn ($fh, "eval"); - - } + - } + View Code2) zhuce.html
1<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>5<title> Form Validation </title>6<script src= ". /.. /.. /.. /.. /jquery-1.11.2.min.js ">7</script>89 Ten<body> One<form action= "__action__" method= "POST" > A<div> Username: <input type= "text" id= "UID" name= "UID"/><span id= "ts" ></SPAN></DIV><BR/ > -<div> Secret Code: <input type= "text" name= "pwd"/></div> -<div> Confirm Password: <input type= "text" name= "pwd1"/></div><br/> the<div> Age: <input type= "text" Name= "ages"/></div><br/> -<div> Email: <input type= "text" name= "email"/></div><br/> -<div> Name: <input type= "text" name= "name"/></div><br/> -<!--display error messages-- +<div style= "width:200px; height:30px; border: #F00 solid 2px; line-height:30px; Vertical-align:middle; Text-align:center; " ><{$error}></div><br/> -<div><input type= "Submit" value= "register"/></div> +</form> A</body> at<script type= "Text/javascript" > -$ (document). Ready (function(e) { -$ ("#uid"). Blur (function(){ - varuid=$ (This).Val (); -$.Ajax ({ -URL: "__controller__/yhm", inData:{uid:uid},//the parameter name to be passed here must match the name in the form. -Type: "POST", toDataType: "TEXT", +Successfunction(data) { -$ ("#ts").HTML (data); the } * $ });Panax Notoginseng - }) the }); + A</script> theView Code
Display effect:
4.Session and CookiesSession Support:
The system provides the perfect support for session management and operation, all of which can be completed by a built-in session function, which can complete the session setup, fetch, delete and manage operation.
5. Prevent users from bypassing the login direct access operation method
Do a controller of the parent class, in the parent class to write a construction method, the construction method inside to determine whether there is no value in the session, if no value ... If there is a value ...
Thinkphp Scattered knowledge points