tp框架之数据添加

1.数组添加

//$attr = array("Code"=>"n088","Name"=>"哈萨克族");

//$nation->add($attr);

 

2.AR添加

//$nation->Code = "n087";
//$nation->Name = "朝鲜族";
//$nation->add();

 

3.自动加载表单

public function zhuCe()
    {
        //实现两个逻辑
        //1.显示注册页面 2.向数据库添加内容
        
        if(empty($_POST))
        {
            //显示页面
            $this->show();
        }
        else
        {
            $n = D("Nation");
            $n->create();//自动收集表单.前提是必须有post数据
            
            $z = $n->add();
            
            if($z)
            {
                $this->success("添加成功","zhuCe");
            }
            else
            {
                $this->error("添加失败!");
            }
        }
        
    }
View Code

 

4.页面跳转

//$this->redirect('zhuCe', array(), 5, '页面跳转中...');  //跳转页面  可传的参数  过几秒执行  提示语

 

5.跨页面参数接收

public function canShu($id=0)
    {
        //echo $id;
    }

 

posted @ 2016-12-22 18:37  哔哩哔哩干杯  阅读(330)  评论(0编辑  收藏  举报