Thinkphp Study Summary

Source: Internet
Author: User

thinkphp3.2 Handbook Catalog: http://www.kancloud.cn/manual/thinkphp/1678

First, page jump

1.URL mode is used to direct requests to modules, controllers, and operations, such as PathInfo mode: The http://localhost/index.php/home/user/login/var/value/method does not exist, then the template

2. Page Jump $this->success ("New Success", '/user/index ');

$this->success ("Add Success", U (' Office/index ')); Jump method

3. Page redirection $this->redirect ("Office/index"); Jump method

4. Display template $this->display ("/office/officejudge");

$this->display (' Member:read '); The default view directory is typically

5.ajax return $this->ajaxreturn (eval ("Return $xsq;"));

U method: Default Current module, U (' Office/index ') for Office Controller index method

Second, variable acquisition

1. Background access, recommended I method, note how to submit how to take, value for square brackets

$id = $_get[' id ']; Equivalent to $id = I (' Get.id, "") does not exist return ""

2. Front desk display

$this->assign ("condition", $condition);

Direct $ value value= "{$condition}"

Array <volist name= "office_list" id= "VO" >

<tr><td>{$num ++}</td>

<td>{$vo .name}</td>

<td><a href= "__controller__/deleteofficejudge?id={$vo. ID}" onclick= "Del ()" > Delete </a></td> </tr></volist>

Iii. Configuration Files

$DB _config = Array (

' Db_type ' = ' mysql ',//database type

' Db_host ' = ' 127.0.0.1 ',//server address

' Db_name ' = ' evalute ',//database name

' Db_user ' = ' root ',//user name

' Db_pwd ' and ' = ',//password

' Db_port ' = 3306,//Port

' Db_prefix ' = ' think_ ',//database table prefix

' Db_charset ' = ' utf8 ',//Character Set

' Db_debug ' + TRUE,//Database debug mode can log SQL logs after opening

);

$URL _config = Array (

' Url_module ' = 0,

' Default_filter ' = ' Htmlspecialchars,trim ',

);

Return Array_merge ($DB _config, $URL _config);

Four, curd operation

Instantiation: D is going to instantiate the corresponding model, which is validated with it. M only to the database additions and deletions to check and change.

Data modification: Automatic authentication, token verification (anti-duplication commit) and auto-completion in the Create method. $User->create ($data), you can assign a value to $user first, or you can assign a value to the $data array. $User->add (); Write to the database, because the add does not pass data. You can also not create a direct add ($data). Save similar.

Data read: coherent operation; query conditions try to use array mode, which is a safer way;

$Model->where ("id=%d and Username= '%s '", Array ($id, $username))->select ();

Data deletion: $Form->delete (5), which deletes a primary key of 5

Removal tips for pages

Function del () {

if (!confirm ("Confirm to delete?") ")){

Window.event.returnValue = false;

}

}

Five, view model

namespace Home\model;

Use Think\model\viewmodel;

Class Contentmodel extends viewmodel{

Public $viewFields = Array (

' Paper ' =>array (' name '), ' pcontent ' =>array (' id ', ' qorder ', ' Paperid ', ' itemId ', ' _on ' = ' paper.id= ') Pcontent.paperid '),

' Question ' =>array (' subname ', ' option ' = ' Radio ', ' Startdesc ', ' enddesc ', ' _on ' = ' pcontent.qid=question.id ') ),

' Type ' =>array (' name ' = = ' type ', ' _on ' = ' type.id=question.type '),

' Item ' =>array (' name ' = ' itemname ', ' _on ' = ' pcontent.itemid=item.id '),

);

}

Vi. template replacement-special strings

__APP__: Will replace the current app's URL address (without domain name)

__MODULE__: Will replace the URL address of the current module (excluding domain name)

__CONTROLLER__ (__ or __url__ compatibility considerations): Will replace the current controller's URL address (without domain name)

__ACTION__: Will replace the current operation's URL address (without domain name)

__SELF__: Will replace the current page URL

__PUBLIC__: The common directory that will be replaced with the current site is usually/public/

Vii. File Upload

<input type= "file" name= "Photo"/>

$config = Array (

' MaxSize ' = 3145728,

' RootPath ' = './uploads/',

' Savepath ' = ',

' Savename ' = = Array (' uniqid ', '),

' exts ' = = Array (' jpg ', ' gif ', ' PNG ', ' jpeg '),

' Autosub ' = true,

' SubName ' = Array (' Date ', ' YMD '),

);

$upload = new \think\upload ($config);//instantiation of upload class

$info = $upload->upload ($_files[' photo ');

if (! $info) {//Upload error error message

$this->error ($upload->geterror ());

}else{//Upload successfully uploaded file information

echo $info [' Savepath ']. $info [' Savename '];

}

Eight, verification code

Public Function Verify () {

$Verify = new \think\verify;

$Verify->USEIMGBG = true;

Ob_clean ();//Discard the contents of the output buffer

$Verify->entry ();

}

Ix. Introduction of menu Files

<include file= "public/header.html"/>

Ten, when modified-radio box, check box

Single-Use EQ

<select name= "type" value= "{$question _info.type}" >

<volist name= "type_list" id= "T" >{$t. ID}

<eq name= "t.id" value= "$question _info.type" >

<option value= "{$t. ID}" selected= "selected" >{$t .name}</option>

<else/>

<option value= "{$t. ID}" >{$t .name}</option>

</eq>

</volist>

</select>

check box with in

<volist name= "Radio_list" id= "R" >

<in name= "r.id" value= "$question _info.option" >

<input name= "radio[" "type=" checkbox "value=" {$r. ID} "checked=" Checked ">{$r. Opname}

<else/>

<input name= "radio[]" type= "checkbox" value= "{$r. ID}" >{$r. Opname}

</in>

</volist>

Handling of Value after check box submission

foreach ($_post[' Radio ') as $key = = $value) {

$option = $option. $value. ",";

}

$data [' option '] = substr ($option, 0,strlen ($option)-1);

Split string

if ($question _info[' option ']! = null) {

$question _info[' option ' = Explode (",", $question _info[' option ');}

Xi. Verify that the user name already exists ajax+jquery

return value Echo json_encode ($user _list);

function CheckName () {

$.ajax ({

Type: "POST",

URL: "__controller__/testuser",

Data: "Uname=" +$ (' #uname '). Val (),

Success:function (msg) {

for (var mi in eval (' (' +msg+ ') ') {

Alert (mi+ "-and" +eval (' (' +msg+ ') ') [MI]);

// }

if (eval (' (' +msg+ ') ')! = null) {

$ (' #notice '). HTML ("already exists");

}else{

$ (' #notice '). HTML ("can be used");

}

}

});

}

12. Paging

$count = $type->count ();

$Page = new \think\page ($count, 2);

$Page-Setconfig (' header ', ' Total%total_row% ');

$Page-Setconfig (' first ', ' home ');

$Page-Setconfig (' Last ', ' Total%total_page% page ');

$Page-Setconfig (' prev ', ' prev ');

$Page-Setconfig (' Next ', ' next page ');

$Page-setconfig (' link ', ' indexpagenumb ');//pagenumb will replace the page number

$Page-Setconfig (' theme ', '%header%%first%%up_page%%link_page%%down_page%%end% ');

$show = $Page->show ();

$type _list = $type->order (' name desc ')->limit ($Page->firstrow. ', '. $Page->listrows)->select ();

$this->assign ("Type_list", $type _list);

$num = $Page->firstrow + 1;//serial number

$this->assign ("num", $num);

$this->assign ("page", $show);

<TR><TD colspan= "3" ><div>{$page}</div></td></tr>

Page with condition, the form form of a conditional query is submitted in get form

13. Custom Menu

Array in 1.js, note the a capitalization of array

var menus = new Array ();

Menus[0] = {"id": 1, "name": "Sport", "Ismenu": "1"}

Menus[1] = {"id": 2, "name": "Music", "Ismenu": "1"}

2.js information about the control where the event occurred

Onclick= "Del (This)"

del var myid = obj.id;

3.jquery fetching the value of the control

$ ("#xsq"). attr ("value", value);

$ ("#xsq"). Val ();

14. Commissioning

F12 look at the elements, see the network transmission

$this->show ("2333");

Var_dump ($a); PHP notation, dump ($a) works the same in thinkphp

Thinkphp Study Summary

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.