亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

產(chǎn)品模塊中添加和刪除功能

Original 2019-03-30 10:12:23 310
abstract:public function DoAdd(){    // 獲取提交出來的數(shù)據(jù)    $data = Request::param();    // 將產(chǎn)品名獨立出來    $title = $data['title'];    // 利用產(chǎn)品名作為查詢條件查詢對應(yīng)的數(shù)據(jù) &nbs



public function DoAdd()
{
   // 獲取提交出來的數(shù)據(jù)
   $data = Request::param();
   // 將產(chǎn)品名獨立出來
   $title = $data['title'];
   // 利用產(chǎn)品名作為查詢條件查詢對應(yīng)的數(shù)據(jù)
   $info = ProductModel::where('title', $title)->find();
   // 判斷是否查詢到相同的產(chǎn)品名稱
   if ($info == true) {
       // 返回提示信息
       return ['res' => 0, 'msg' => '產(chǎn)品標(biāo)題重復(fù)!'];
   }
   // 加入添加時間
   $data['time'] = time();
   // 添加發(fā)布管理員
   $data['username'] = Session::get('username');
   // 實例化模型
   $product = new ProductModel();
   // 進行添加并驗證
   if ($product->save($data)) {
       // 返回提示信息
       return ['res' => 1, 'msg' => '發(fā)布成功!'];
   } else {
       // 返回提示信息
       return ['res' => 0, 'msg' => '發(fā)布失??!'];
   }
}


public function del()
{
   // 獲取需要刪除的產(chǎn)品id
   $proId = Request::param('id');
   $product = new ProductModel();
   if ($product->destroy($proId)) {
       return ['res'=>1,'msg'=>'刪除成功!'];
   }

Correcting teacher:天蓬老師Correction time:2019-03-30 10:21:18
Teacher's summary:在方法中, 盡可能避免直接使用new, $product = new ProductModel();, 可以通過對象注入, 或者 Facade 方式進行調(diào)用

Release Notes

Popular Entries