//例题
//显示所有数据
public function ShowInfo()
{
$model = D("Info");
$attr = $model->field("Info.Code as InfoCode,Info.Name as InfoName,Info.Sex,Nation.Name as NationName,Info.Birthday ")->join("Nation on Info.Nation=Nation.Code")->select();
$this->assign("shuju",$attr);
$this->display();
//var\_dump($attr);
}
//删除数据的操作方法
public function ShanChu($code)
{
$model = D("Info");
$z = $model->delete($code);
if($z)
{
$this->success("删除成功",U("ShowInfo"));
}
else
{
$this->error("删除失败");
}
}
代号 | 姓名 | 性别 | 民族 | 生日 | 操作 |
<{$v.infocode}> | <{$v.infoname}> | <{$v\["sex"\]?"男":"女"}> | <{$v.nationname}> | <{$v.birthday}> | 删除 修改 |
//删除数据的操作方法
public function ShanChu($code)
{
$model = D("Info");
$z = $model->delete($code);
if($z)
{
$this->success("删除成功",U("ShowInfo"));
}
else
{
$this->error("删除失败");
}
}
//添加数据的操作方法
public function TianJia()
{
if(empty($_POST))
{
$model = D("Nation");
$attrn = $model->select();
$this->assign("minzu",$attrn);
$this->display();
}
else
{
$model = D("Info");
$model->create();//自动收集表单并且创建数据
$model->Sex = $_POST["Sex"]=="男"?true:false;
$z = $model->add();
if($z)
{
$this->success("添加成功","TianJia");
}
else
{
$this->error("添加失败");
}
}
}
//修改数据的操作方法
public function XiuGai($code)
{
$modeli = D("Info");
$modeln = D("Nation");
if(empty($_POST))
{
$attri = $modeli->find($code);
$attrn = $modeln->select();
$this->assign("info",$attri);
$this->assign("nation",$attrn);
$this->display();
}
else
{
$modeli->create();
$modeli->Sex = $\_POST\["Sex"\]=="男"?true:false;
$z = $modeli->save();
if($z)
{
$this->success("修改成功!",U("ShowInfo"));
}
else
{
$this->error("修改失败");
}
}
}
显示效果依次如下:
手机扫一扫
移动阅读更方便
你可能感兴趣的文章