请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

没办法调试出来。运行后出现页面错误

<?php


namespace app\api\controller\v1;

use app\api\validate\IDMustBePostiveInt;
use app\api\validate\TestValidate;
use think\Validate;
class Banner
{
   /**
    * 获取指定id的banner信息
    * @url /banner/:id
    * @http GEt
    * @id banner的id号
    *i
    */
  public function getBanner($id)
  {
      (new IDMustBePostiveInt())->goCheck();//拦截器
      $c = 1;
     //$validate = new IDMustBePostiveInt();
     //$validate->goCheck();
    // $banner = BannerModel::getBannerById($id);
    // if(!$banner){
      //   throw new MissException([
        //     'msg' => '请求banner不存在',
        //     'errorCode' => 40000
        // ]);
    // }
    // return $banner;

  }
}

<?php


namespace app\api\validate;

use think\Exception;
use think\Request;
use think\Validate;


class BaseValidate extends Validate
{
   public function goCheck()
   {
       $request = Request::instance();
       $params = $request->param();

       $result = $this->check($params);
       if (!$result){
          $error = $this->error;
          throw new Exception($error);
       }
       else{
           return true;
       }
   }
}

<?php


namespace app\api\validate;


use think\Validate;


class IDMustBePostiveInt extends Validate
{
   protected $rule = [
       'id' => 'require|isPositiveInteger'
   ];

   protected function isPositiveInteger($value, $rule = '', $data = '', $field = '')
   {
       if (is_numeric($value) && is_int($value + 0) && ($value + 0)>0) {
           return true;
       }
       else {
           return $field .'必须是正整数';
       }
   }
}

正在回答 回答被采纳积分+3

1回答

7七月 2019-04-13 14:36:06

这我怎么帮你呢。。。。错误是什么?调试的问题必须要调试解决,看代码也看不出来的。

0 回复 有任何疑惑可以回复我~
  • 提问者 慕慕0284577 #1
    无法显示'必须是正整数',显示的是页面错误
    回复 有任何疑惑可以回复我~ 2019-04-13 15:16:43
  • 7七月 回复 提问者 慕慕0284577 #2
    能不能把错误截图看看呢,这个这样弄真的解决不了问题啊,朋友
    回复 有任何疑惑可以回复我~ 2019-04-13 22:36:16
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信