Commit 3ada217b authored by rlgy's avatar rlgy

update

parent af582089
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午10:29
*/
namespace api\base;
use yii\web\Controller;
class BaseController extends Controller
{
public $start;
public $end;
public function beforeAction($action)
{
$this->start = microtime(true);
return parent::beforeAction($action); // TODO: Change the autogenerated stub
}
public function afterAction($action, $result)
{
$this->end = microtime(true);
return parent::afterAction($action, $result); // TODO: Change the autogenerated stub
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午1:28
*/
namespace api\base;
use yii\web\Response;
class BaseResponse extends Response
{
public function send()
{
//错误处理
$excpetion = \Yii::$app->errorHandler->exception;
if ($excpetion !== null) {
$this->data = [
'code' => $excpetion->getCode(),
'msg' => $excpetion->getMessage(),
'line' => $excpetion->getLine(),
'file' => $excpetion->getFile(),
];
}
//TODO 在这里对数据进行format,这样控制器中可以直接return一个array,保存到数据域data中即可,eg:['code'=>0,'data'=>$data]
$data = \Yii::$app->response->data;
if (empty($data)) {
$return['code'] = 1;
$return['msg'] = '数据为空';
} elseif (is_array($data) && !isset($data['code'])) {
$return['code'] = 0;
$return['count'] = count($data);
$return['data'] = $data;
} else {
$return = $data;
}
if (YII_ENV_DEV) {
$return['time'] = \Yii::$app->controller->end - \Yii::$app->controller->start;
}
\Yii::$app->response->data = $return;
parent::send();
}
}
\ No newline at end of file
main-local.php
params-local.php
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午10:27
*/
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午10:26
*/
$params = array_merge(
require __DIR__ . '/../../common/config/params.php',
require __DIR__ . '/../../common/config/params-local.php',
require __DIR__ . '/params.php',
require __DIR__ . '/params-local.php'
);
return [
'id' => 'app-api',
'basePath' => dirname(__DIR__),
'timeZone' => 'Etc/GMT-8',
'controllerNamespace' => 'api\controllers',
'bootstrap' => ['log'],
'defaultRoute' => 'site/index',
'layout' => false,
'modules' => [],
'components' => [
'request' => [
'baseUrl' => '/interface',
'cookieValidationKey' => '123456',
'enableCsrfValidation' => false,
'parsers' => [
'application/json' => [
'class' => 'yii\web\JsonParser',
'throwException' => false,//json格式错误不报错
],
],
],
'response' => [
'class' => 'api\base\BaseResponse',
'format' => 'json',
'charset' => 'UTF-8',
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
'params' => $params,
];
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午10:31
*/
return [
'feixiaohao_domain' => 'https://www.feixiaohao.com',
'feixiaohao_page' => [
'assets' => '/assets/',//代币
'currencies' => '/currencies/',//币种详情
'coinmarket' => '/coinmarket/',//上市交易所
],
];
\ No newline at end of file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午10:26
*/
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
require __DIR__ . '/../../common/config/bootstrap.php';
require __DIR__ . '/../config/bootstrap.php';
$config = yii\helpers\ArrayHelper::merge(
require __DIR__ . '/../../common/config/main.php',
require __DIR__ . '/../../common/config/main-local.php',
require __DIR__ . '/../config/main.php',
require __DIR__ . '/../config/main-local.php'
);
//不需要rbac验证权限
unset($config['as rbac']);
//没有登录状态
unset($config['as check']);
(new yii\web\Application($config))->run();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment