Heim  >  Artikel  >  Backend-Entwicklung  >  ThinkPHP框架学习之CRUD_PHP教程

ThinkPHP框架学习之CRUD_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:32:12940Durchsuche

User模块UserAction.class.php

<?php
class UserAction extends Action {
	public function index(){
		$m=M('User');//操作的数据库表
		$arr=$m->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

<html>
<head>
	<title></title>
	<script>
		function jump(){
			window.location='__URL__/addform';
		}
	</script>
</head>
<body>
	<table border="1">
		<tr>
			<th>ID号</th>
			<th>用户名</th>
			<th>性别</th>
			<th>操作</th>
		</tr>
		<volist name='data' id='vo'>
		<tr>
			<td>{$vo.id}</td>
			<td>{$vo.username}</td>
			<td>{$vo.sex}</td>
			<td>删除|修改</td>
		</tr>
		</volist>
	</table>
	<button onclick="jump()">添加用户</button>
</body>
</html>

添加表单模板addform.html

<html>
<head>
	<title></title>
</head>
<body>
		
</body>
</html>






www.bkjia.comtruehttp://www.bkjia.com/PHPjc/756256.htmlTechArticleUser模块UserAction.class.php select();//查询数据库$this->assign('data',$arr);//$this->display();}/* * 向数据库插入数据 **/public function add(){$m=M('User');$m->user...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn