Skip to content

Commit

Permalink
修复bug,YII2.0.14以后,find方法变化,删除无用代码
Browse files Browse the repository at this point in the history
  • Loading branch information
windhoney committed May 13, 2019
1 parent bd98913 commit 6690446
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 97 deletions.
14 changes: 7 additions & 7 deletions Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ class Modules extends \yii\base\Module
public function init()
{
parent::init();
if (!isset(Yii::$app->i18n->translations['rbac-admin'])) {
Yii::$app->i18n->translations['rbac-admin'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en',
'basePath' => '@mdm/admin/messages'
];
}
// if (!isset(Yii::$app->i18n->translations['rbac-admin'])) {
// Yii::$app->i18n->translations['rbac-admin'] = [
// 'class' => 'yii\i18n\PhpMessageSource',
// 'sourceLanguage' => 'en',
// 'basePath' => '@mdm/admin/messages'
// ];
// }
$userClass = ArrayHelper::getValue(Yii::$app->components, 'user.identityClass');
if ($this->defaultRoute == 'default' && $userClass && is_subclass_of($userClass, 'yii\db\BaseActiveRecord')) {
$this->defaultRoute = 'assignment';
Expand Down
7 changes: 3 additions & 4 deletions components/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ public function actionCreate()
{
$res = $this->auth_item_model->addPermission($this->type);
Helper::invalidate();
if ( !$res) {
RbacHelper::error();
}
if ($this->type == 1) {
if ( !$res) {
RbacHelper::error();
}

return ArrayHelper::toArray($res['_item']);
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"authors": [
{
"name": "new7",
"name": "windhoney",
"email": "524415250@qq.com"
}
],
Expand Down
13 changes: 7 additions & 6 deletions controllers/base/ApiController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<?php
/**
* 所有接口基类,授权验证,格式设定
*
* @author zhanghongwei
*/

namespace wind\rest\controllers\base;

Expand All @@ -16,6 +11,12 @@
use filsh\yii2\oauth2server\filters\auth\CompositeAuth;
use yii\web\UnauthorizedHttpException;

/**
* 所有接口基类,授权验证,格式设定
*
* @author windhoney
* @package wind\rest\controllers\base
*/
class ApiController extends ActiveController
{

Expand Down Expand Up @@ -105,4 +106,4 @@ public function afterAction($action, $result)

return $this->serializeData($data);
}
}
}
14 changes: 7 additions & 7 deletions helper/RbacHelper.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/**
* 公共方法
*
* @author zhanghongwei
*/

namespace wind\rest\helper;

use yii\log\FileTarget;

/**
* 公共方法
* @author windhoney
* @package wind\rest\helper
*/
class RbacHelper
{

Expand Down Expand Up @@ -82,7 +82,7 @@ public static function error($code = 400, $msg = '非法参数')
* @param string $action
* @param string $file_name
*/
public static function recordLog($message, $action = 'application', $file_name = "lamp")
public static function recordLog($message, $action = 'application', $file_name = "rbac")
{
$message = is_array($message) ? json_encode($message, JSON_UNESCAPED_UNICODE) : $message;
$time = microtime(true);
Expand Down Expand Up @@ -120,4 +120,4 @@ public static function addRoute($dir, $main)

return $main;
}
}
}
11 changes: 3 additions & 8 deletions models/AuthItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function rules()
[['name', 'type'], 'required'],
[
['name'],
'unique',
'checkUnique',
'when' => function () {
return $this->isNewRecord || ($this->_item->name != $this->name);
}
Expand All @@ -81,17 +81,12 @@ public function rules()
/**
* Check role is unique
*/
public function unique()
public function checkUnique()
{
$authManager = Yii::$app->authManager;
$value = $this->name;
if ($authManager->getRole($value) !== null || $authManager->getPermission($value) !== null) {
$message = Yii::t('yii', '{attribute} "{value}" has already been taken.');
$params = [
'attribute' => $this->getAttributeLabel('name'),
'value' => $value,
];
$this->addError('name', Yii::$app->getI18n()->format($message, $params, Yii::$app->language));
$this->addError('name');
}
}

Expand Down
64 changes: 0 additions & 64 deletions models/Blog.php

This file was deleted.

0 comments on commit 6690446

Please sign in to comment.