Thinkphp Learning Notes (vii) the role of the Create method in the instantiation and the use of the token ____php

Source: Internet
Author: User
Tags md5 php class

The success template, which can be searched in example in thinkphp, and placed in public under the TPL default


Create uses

<?php class Curdaction extends action{//creation and additions and deletions to//create ()//creation will complete automatic mapping, autofill, Auto Verify///If the field cache is turned on, match the field, if it does not exist, get the field, and return An array//create method has an automatic token, and putting Md5 encrypted strings into the current session sessions will insert the string before </from> in the point form, with//tokens in session and form that can be configured in conf ; You can use the token <!--{__notoken__}-->//If there are multiple forms on the page, and only one form requires a token, you can display the specified:<!--in this form {__token__}-->//
	Create defaults to get data by the Post method Public Function index () {$this->display ();
		
Public function Add () {$user =new Model (' user '); Do not use the Create method to validate token//if (! $user->autochecktoken ($_post)) {////token authentication failed code;//$this->error ($user->geterr
or ()); }else{////Get information $user//$user->username;//$user->username=md5 ($user->password);///Dump ($user)
;			if ($user->add ()) {//$this->success (' Add success ');//}else{//$this->error ($user->geterror ()); ////returned array information if used with AutoFill, return value and information more if ($vo = $user->create ()) {////This method is a method of executing successfully, giving a variety of information about the page/dump ($VO)
; Successs templates can be thinkphp in theFound in example, put into the public directory in default//$this->success (' create success ');
Obtain the information $user $user->username=md5 ($user->password);
			Dump ($user);
			if ($user->add ()) {$this->success (' Add success ');
			}else{$this->error ($user->geterror ());
			}}else {//If execution fails, the code will not continue backward/dump ($VO);//dump ($user);
		The error template can be found in the thinkphp example and placed into the public directory in default $this->error ($user->geterror ()); }}}?>

Index.html

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

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.