Controller.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Leo
  5. * Date: 2017/9/3
  6. * Time: 下午3:05
  7. */
  8. namespace common\components;
  9. use common\helpers\Tool;
  10. use yii\base\ActionEvent;
  11. use yii\helpers\Json;
  12. use yii\helpers\Url;
  13. class Controller extends \yii\web\Controller {
  14. /**
  15. * @return array
  16. */
  17. public function actions() {
  18. return [
  19. 'captcha' => [
  20. 'class' => 'common\helpers\CaptchaAction',
  21. 'width' => 120,
  22. 'height' => 40,
  23. 'padding' => 0,
  24. 'minLength' => 4,
  25. 'maxLength' => 4,
  26. 'offset'=>8, //设置字符偏移量 有效果
  27. 'testLimit'=>1,
  28. ],
  29. ];
  30. }
  31. /**
  32. * 不允许直接访问ajax页面
  33. * @param $action
  34. * @return bool
  35. * @throws \yii\web\BadRequestHttpException
  36. */
  37. protected function checkAjax(&$action){
  38. $currentAction = $action->id;
  39. if(strpos($currentAction ,'ajax-')===0){
  40. if(!\Yii::$app->request->getIsAjax()){
  41. throw new \yii\web\BadRequestHttpException('无法完成您的请求');
  42. }
  43. }
  44. return true;
  45. }
  46. }