Controller.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. 'backColor' => 0x000000,//背景颜色
  22. 'foreColor' => 0xffffff, //字体颜色
  23. 'width' => 120,
  24. 'height' => 40,
  25. 'padding' => 0,
  26. 'minLength' => 4,
  27. 'maxLength' => 4,
  28. 'offset'=>8, //设置字符偏移量 有效果
  29. 'testLimit'=>1,
  30. ],
  31. ];
  32. }
  33. /**
  34. * 不允许直接访问ajax页面
  35. * @param $action
  36. * @return bool
  37. * @throws \yii\web\BadRequestHttpException
  38. */
  39. protected function checkAjax(&$action){
  40. $currentAction = $action->id;
  41. if(strpos($currentAction ,'ajax-')===0){
  42. if(!\Yii::$app->request->getIsAjax()){
  43. throw new \yii\web\BadRequestHttpException('无法完成您的请求');
  44. }
  45. }
  46. return true;
  47. }
  48. }