首页显示
<!DOCTYPE html> <html> <head> <style> ul { list-style-type:none; margin:0; padding:0; overflow:hidden; } li { float:left; } a:link,a:visited { display:block; width:120px; font-weight:bold; color:#FFFFFF; background-color:#bebebe; text-align:center; padding:4px; text-decoration:none; text-transform:uppercase; } a:hover,a:active { background-color:#cc0000; } </style> </head> <body> <ul> <li><a href="{:U(‘Index/index‘)}">显示用户</a></li> <li><a href="{:U(‘Index/add‘)}">添加用户</a></li> <li><a href="{:U(‘Index/del‘)}">删除用户</a></li> <li><a href="#about">超级用户</a></li> </ul> <br> <foreach name="div" item="vo"> <div style=border-style:outset> 用户:{$vo.username} </div> <br> </foreach> </body> </html>
添加页
<!DOCTYPE html> <html> <head> <style> ul { list-style-type:none; margin:0; padding:0; overflow:hidden; } li { float:left; } a:link,a:visited { display:block; width:120px; font-weight:bold; color:#FFFFFF; background-color:#bebebe; text-align:center; padding:4px; text-decoration:none; text-transform:uppercase; } a:hover,a:active { background-color:#cc0000; } </style> </head> <body> <ul> <li><a href="{:U(‘Index/index‘)}">显示用户</a></li> <li><a href="{:U(‘Index/add‘)}">添加用户</a></li> <li><a href="{:U(‘Index/del‘)}">删除用户</a></li> <li><a href="#about">超级用户</a></li> </ul> <br> <form action="{:U(‘Index/addadd‘)}" method="post"> 用户名: <input type="text" name="name"><br><br> 密码: <input type="text" name="password"><br><br> <input type="submit"> </form> </body> </html>
删除页
<!DOCTYPE html> <html> <head> <style> ul { list-style-type:none; margin:0; padding:0; overflow:hidden; } li { float:left; } a:link,a:visited { display:block; width:120px; font-weight:bold; color:#FFFFFF; background-color:#bebebe; text-align:center; padding:4px; text-decoration:none; text-transform:uppercase; } a:hover,a:active { background-color:#cc0000; } </style> </head> <body> <ul> <li><a href="{:U(‘Index/index‘)}">显示用户</a></li> <li><a href="{:U(‘Index/add‘)}">添加用户</a></li> <li><a href="{:U(‘Index/del‘)}">删除用户</a></li> <li><a href="#about">超级用户</a></li> </ul> <br> <foreach name="div" item="vo"> <div style=border-style:outset> 用户:{$vo.username} <a href="{:U(‘Index/deldel‘,array(‘username‘=>$vo[‘username‘]))}">删除此项</a> </div> <br> </foreach> </body> </html>
控制器
<?php // 本类由系统自动生成,仅供测试用途 class IndexAction extends Action { //显示用户 public function index(){ header("Content-Type:text/html; charset=utf-8"); $User = M("user"); // 实例化模型类 $data = $User->select(); $this->assign(‘div‘,$data); $this->display(); } public function add(){ $this->display(‘tpl/add‘); } public function addadd(){ $data["username"] = $_POST[‘name‘];//接收用户名 $data["encryptedPassword"] = I(‘password‘,‘‘,‘md5‘); $data["creationDate"]= time(); $data["modificationDate"]= time(); $User = M(‘user‘); $User->add($data); $t = time(); //$User = D("User");if($vo=$User->create()){ //if($User->add()){ //$this->success(‘添加用户成功‘); //}else{ //$this->error(‘添加用户失败‘); //} //}else{ //$this->error($User->getError()); //} echo ‘Now: ‘. date(‘Y-m-d‘) ."\n"; dump($data); $this->redirect(‘Index/add‘); } public function del(){ header("Content-Type:text/html; charset=utf-8"); $User = M("user"); // 实例化模型类 $data = $User->select(); $this->assign(‘div‘,$data); $this->display(‘tpl/del‘); } public function deldel(){ $username = I(‘username‘);//接收id $del = M(‘user‘); $del->where("username = ‘$username‘")->delete(); //echo ‘删除成功!‘; dump($username); dump($del); $this->redirect(‘Index/del‘); } }
设置器
<?php return array( //‘配置项‘=>‘配置值‘ //‘USERNAME‘=>‘admin‘, //赋值 //数据库配置信息 ‘DB_TYPE‘ => ‘mysql‘, // 数据库类型 ‘DB_HOST‘ => ‘localhost‘, // 服务器地址 ‘DB_NAME‘ => ‘openfire‘, // 数据库名 ‘DB_USER‘ => ‘root‘, // 用户名 ‘DB_PWD‘ => ‘root‘, // 密码 ‘DB_PORT‘ => 3306, // 端口 ‘DB_PREFIX‘ => ‘of‘, // 数据库表前缀 //其他项目配置参数 // ... ); ?>
时间: 2024-11-07 16:29:18