管理后台的---增删改查代码结构

后台一般只需要实现功能,没有特殊需求,代码结构基本一致

1,添加数据和显示列表在同一个页面情况

<?php
/*
*
*/
class subject{

	/*
	*
	*/
	public function index(){
		$this->title = 'title';
		// 增/删/改
		$this->index_cud();
		
		// 搜索
		if( isset($_POST['searchKey']) && !empty($_POST['searchKey']) ){
			$searchKey = trim($_POST['searchKey']);
			//
		}
		
		
		// 数据
		$subjectM = new SubjectModel();
		// where(conditon) 
		$subjectD = $subjectM->findAll();
		
		$this->assign('subjectD', $subjectD);
		$this->display();
	}
	
	
	/*
	 *  增/删/改
	 */
	private function index_cud(){
		// 编辑
		if( isset($_POST['edit'],$_POST['id']) && $_POST['id']>0 ){
			$id = intval($_POST['id']);
			
			
			$this->succMsg('编辑成功');
			return true;
		}
		
		// 新增
		if( isset($_POST['title']){
			// 字段判断
			// $this->errMsg('不能为空');
		
			
			$this->succMsg('新增成功');
			return $newId;
		}
		
		// 删除
		if( isset ($_GET['del'],$_GET['id']) && $_POST['id']>0  ){
			$id = intval($_POST['id']);
			
			
			$this->succMsg('删除成功');
			return true;
		}
		
	}
}

2. 添加页面,显示页面不在一个页面

3.

猜你喜欢

转载自ww111.iteye.com/blog/1162897