1. 程式人生 > >thinkphp5 之資料操作和模板輸出

thinkphp5 之資料操作和模板輸出

       $result=Db::table('ims_ewei_shop_ceshib')->select();
        $this->assign('mylist',$result);
        return view('helloworld');
        /*查詢資料*/
         // $map=array(
         //    'status'=>1,
         // );
         // $result=db('ims_ewei_shop_ceshib')->where($map)->select();
         /*新增一條資料*/
// $insertdata=array( // 'name'=>'g', // 'age'=>24, // 'status'=>1, // ); /*返回新增成功的條數*/ // $result=db('ims_ewei_shop_ceshib')->insert($insertdata); /*返回新增資料的自增主鍵*/ // $userid=db('ims_ewei_shop_ceshib')->insertGetId($insertdata); /*新增多條資料*/
// $muchdata=array( // '0'=>array( // 'name'=>'h', // 'age'=>24, // 'status'=>0, // ), // '1'=>array( // 'name'=>'i', // 'age'=>24, // 'status'
=>1, // ), // ); // $res=db('ims_ewei_shop_ceshib')->insertAll($muchdata); // /*更新資料*/ // $updata=array( // 'name'=>'nji', // 'age'=>23, // ); // $map=array( // 'id'=>4, // ); // /*更新資料*/ // $res=db('ims_ewei_shop_ceshib')->where($map)->update($updata); /*更新某個欄位的值*/ // $fileddata=array( // 'name'=>'today' // ); // $map=array( // 'id'=>6, // ); // $res=db('ims_ewei_shop_ceshib')->where($map)->setField($fileddata); /*給變數賦值要加 \think\Controller*/ // $res='helloworld'; // $this->assign('result',$res); /*輸出模板*/ // return view('helloworld'); // return $this->fetch('helloworld'); /*輸出模板和變數*/ // return $this->fetch('helloworld',array('name'=>'ieroe')); // return view('helloworld',array('name'=>'aurhpar')); /*使用fetch輸出模板和變數(變數用陣列傳值)頭部加use think\view;*/ // $view = new View(); // return $view->fetch('helloworld',array('name'=>'11111343fff')); /*直接顯示內容到模板上*/ // return $this->display('helloworld');