thinkphp3.1.3 的404页面和assign()方法和add()方法

404页面和assign()方法和add()方法

IS_POST 判断post值是否存在 不存在返回假

If(!IS_POST) _404(‘页面不存在’);  或者halt(‘页面不存在’)

    Add方法进行写入数据库

if(!IS_POST)_404('页面不存在',U('index'));

$data=array(

    'username'=>I('username','','htmlspecialchars'),

    'content'=>I('content','','htmlspecialchars'),

    'time'=>time(),

);

if(M('wish')->data($data)->add()){

    $this->success('发布成功,请返回',U('index'));

}else{

  $this->error('发布不成功',U('index'));

M(’wish’)=new MODEL(‘wish’)等于new数据模型

$re=M('wish')->where('id')->delete(); 清空表数据,因为删除表是危险操作必须加where条件

M(‘wish’)->select() 查询所有结果

Thinkphp3.1.3 使用 $this->assign(‘wish’,M(‘wish’)->data($data)->select())->display() 整体查询输入

使用 foreach 循环

  {$v['username']}

No.{$v['id']}

      {$v.time|date='y-m-d H:i',###}时间戳格式化要加三个###

‘TMPL_VAR_IDENTIFY’=>’array’  方法向模板传递的都是数组

你可能感兴趣的:(thinkphp3.1.3 的404页面和assign()方法和add()方法)