Crying, please give me an answer. How to convert the join method of the controller to the model method?
小阿**
小阿** 2020-03-06 11:55:25
0
2
910

There are three tables

Commodity table goods: The fields are id, goods_id, goods_name, fee, duration, unit, create_time

Software upgrade table upgrade: The fields are id, app_name, china_name , app_version, force_upgrade, download_url, create_time

Software name price list upgrade_access: The fields are id, gid (goods table id), upgrade_id (upgrade table id)


The approximate requirements are : Find the app_name of the software upgrade table corresponding to the product table goods, and then use app_name to find the software name and price detail table upgrade_access. The upgrade_id is the same data corresponding to the product table goods.
I feel like you can’t understand that I use the controller method to search. Out

$data = Db::name('upgrade_access') ->alias('a') ->join('goods b','b.id = a.gid') - >join('upgrade c','c.id = a.upgrade_id') ->where(['app_name'=>$appname]) ->field('fee,goods_name,duration,unit') ->select();

But what I need now is that my boss doesn’t let me use the controller method and asks me to write it in the model layer and then directly use the model layer method

So the model layer should How to write the api is to customize the input value of app_name and use the value of app_name to find the price information of the goods table

小阿**
小阿**

reply all (2)
对方正在输入....

You can just throw this into the model and use it.

    春风十里吹不动你

    The writing method of the model is not too different from the writing method of the controller. Build a model yourself. Introduce the model. You can search it on Baidu. This is not difficult

      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!