Omission error in thinkphp6.0 rapid development manual (case version)
迷心兔
迷心兔 2020-02-13 16:52:16
0
6
944

Model: It is recommended to change the method name

public function goods_find(){ // $find = Goods::find(6); $find = Goods::where('id',27)->find(); return $find; } public function goods_select(){ // $select = Goods::select(); // $select = Goods::select(6); $select = Goods::where('id','>',7)->select(); // toArray方法将当前的模型实例输出为数组 return $select->toArray(); } public function goods_create(){ $create = Goods::create([ 'cat' => 3, 'title' => '新商品', 'price' => '59.99', 'add_time' => time() ]); echo $create->id; // 可以直接获取自增id return $create; } public function goods_update(){ # 更新方式一(静态方法修改数据,返回的是当前模型的对象实例) // $update=Goods::update( // ['price'=>'99.99'], // ['id'=>22], // ); // return $update; # 更新方式二(这种方式是最佳的更新方式) $user=Goods::find(23); $user->price='102.99'; $save=$user->save(); return $save; } public function goods_delete(){ # 删除方法1(静态方法删除数据,返回的是当前模型的对象实例) $delete = Goods::where('id',3)->delete(); # 删除方法2( 根据主键删除) // $delete = User::destroy(4); return $delete; }


迷心兔
迷心兔

reply all (2)
数据学院

Support one


    欧阳克

    What's wrong with this?

    • reply This is a method name conflict. My running environment displays an error.
      迷心兔 author 2020-02-15 01:27:22
    • reply There are multiple methods here, which method conflicts? Have the methods in the two cases been merged into one file?
      查无此人 author 2020-02-15 14:38:48
    • reply Yes, they are put together in the goods of the model. The tutorial does not mention using *** yet, so I put them together.
      迷心兔 author 2020-02-16 21:20:37
    • reply The tutorial also said where to use it?
      迷心兔 author 2020-02-16 21:23:30
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!