ThinkPHP学習ノート(7)インスタンス化におけるcreateメソッドの役割,およびトークンの使用

2279 ワード

その中のsuccessのテンプレート、ThinkPHPの中のexampleの中で検索することができて、それからtplの下のdefaultの下のPublicの中に入れます
create使用
<?php
class CurdAction extends Action{
	//       
	//create()
	//         、    、    
	//         ,      ,     ,     ,      
	//create        ,    session     Md5                 </from>  ,session form  
	//     conf   ;                    <!--{__NOTOKEN__}-->
	//          ,          ,           :<!--{__TOKEN__}-->
	//create          post  
	public function index() {
		$this->display();
	}
	
	public function add(){
		$user=new Model('User');
		
//		//   create      
//		if (!$user->autoCheckToken($_POST)) {
//			//         ;
//			$this->error($user->getError());
//		}else{
//			//      $user
//			$user->username;
//			$user->username=md5($user->password);
//	//		dump($user);
//			if ($user->add()) {
//				$this->success('    ');
//			}else{
//				$this->error($user->getError());
//			}
//		}
		
		
		//              ,        
		if ($vo=$user->create()) {
//			//              ,          
//			dump($vo);
//			//successs     ThinkPHP example   ,   default  public   
//			$this->success('create  ');
			
			//      $user
			$user->username=md5($user->password);
//			dump($user);
			if ($user->add()) {
				$this->success('    ');
			}else{
				$this->error($user->getError());
			}
		}else {
			//      ,          
//			dump($vo);
//			dump($user);
			//error     ThinkPHP example   ,   default  public   
			$this->error($user->getError());
		}
	}
}
?>

index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CURD</title>
</head>
<body>
<form action="__URL__/add" method="post">
	<input type="text" name="username"/>
	<input type="text" name="password"/>
	<input type="submit" value="  "/>
	<!--{__NOTOKEN__}-->
</form>
</body>
</html>