M.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 97
  5. */
  6. namespace app\demo\controller;
  7. use app\BaseController;
  8. use app\common\business\Demo;
  9. class m extends BaseController{
  10. public function index(){
  11. $categoryId = $this->request->param("category_id",0,"intval");
  12. if(empty($categoryId)){
  13. return show(config("status.error"),"参数错误");
  14. }
  15. $demo = new Demo();
  16. $results = $demo->getDemoDataByCategoryId($categoryId);
  17. return show(config("status.success"),"ok",$results);
  18. //初学者 处理放在一个位置的方式
  19. // //use app\common\model\mysql\Demo;
  20. // //调取数据表对应的的 model ------ 在转移到 business 层
  21. // $model = new Demo();
  22. // $results = $model->getDemoDataByCategoryId($categoryId);
  23. //
  24. // if(empty($results)){
  25. // return show(config("status.error"),"数据为空");
  26. // }
  27. // $cagegorys = config("category");
  28. // foreach ($results as $key=>$result){
  29. // $results[$key]['categoryName'] = $cagegorys[$result['category_id']] ?? '--';
  30. // }
  31. // return show(config("status.success"),"ok",$results);
  32. }
  33. }