| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Leo
- * Date: 2017/9/3
- * Time: 下午3:05
- */
- namespace common\components;
- use common\helpers\Tool;
- use yii\base\ActionEvent;
- use yii\helpers\Json;
- use yii\helpers\Url;
- class Controller extends \yii\web\Controller {
- /**
- * @return array
- */
- public function actions() {
- return [
- 'captcha' => [
- 'class' => 'common\helpers\CaptchaAction',
- 'width' => 120,
- 'height' => 40,
- 'padding' => 0,
- 'minLength' => 4,
- 'maxLength' => 4,
- 'offset'=>8, //设置字符偏移量 有效果
- 'testLimit'=>1,
- ],
- ];
- }
- /**
- * 不允许直接访问ajax页面
- * @param $action
- * @return bool
- * @throws \yii\web\BadRequestHttpException
- */
- protected function checkAjax(&$action){
- $currentAction = $action->id;
- if(strpos($currentAction ,'ajax-')===0){
- if(!\Yii::$app->request->getIsAjax()){
- throw new \yii\web\BadRequestHttpException('无法完成您的请求');
- }
- }
- return true;
- }
- }
|