ThinkPHP框架學習之CRUD

User模塊UserAction.class.php

select();//查詢伺服器
		$this->assign('data',$arr);//
		$this->display();
	}
	
	/*
	 * 向伺服器插入數據
	 **/
	public function add(){
		$m=M('User');
		$m->username=$_POST['username'];
		$m->sex=$_POST['sex'];
		$num=$m->add();
		if ($num>0){
			$this->success('添加成功','index');//添加成功並返回首頁
		}else {
			$this->error('添加失敗');
		}
	}
	/*
	 * 顯示添加表單
	 **/
	public function addform(){
		$this->display();
	}
}
?>

首頁模板文件index.html


	
	<script>
		function jump(){
			window.location='__URL__/addform';
		}
	</script>


	
ID號 用戶名 性別 操作
{$vo.id} {$vo.username} {$vo.sex} 刪除|修改

添加表單模板addform.html


	


	
		姓名:
性別:男 女

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *