<?php
namespace wechat\controllers;

use Yii;
use yii\web\NotFoundHttpException;

class SiteController extends BaseController
{
    /**
     * @inheritdoc
     */
    public function beforeAction($action)
    {
        return true;
    }

    /**
     * @return \yii\web\Response
     */
    public function actionIndex()
    {
        return $this->outJson(1, [], 'ok');
    }

    /**
     * 错误处理器
     * @return \yii\web\Response
     */
    public function actionError()
    {
        $errorHandler = Yii::$app->getErrorHandler();
        $exception = $errorHandler->exception;
        if ($exception == null) {
            $exception = new NotFoundHttpException();
        }

        Yii::$app->getResponse()->setStatusCodeByException($exception);
        return $this->outJson(0, [], Yii::$app->getResponse()->statusText);
    }
}
