Skip to content

Commit 6690446

Browse files
committed
修复bug,YII2.0.14以后,find方法变化,删除无用代码
1 parent bd98913 commit 6690446

File tree

7 files changed

+28
-97
lines changed

7 files changed

+28
-97
lines changed

Modules.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ class Modules extends \yii\base\Module
9494
public function init()
9595
{
9696
parent::init();
97-
if (!isset(Yii::$app->i18n->translations['rbac-admin'])) {
98-
Yii::$app->i18n->translations['rbac-admin'] = [
99-
'class' => 'yii\i18n\PhpMessageSource',
100-
'sourceLanguage' => 'en',
101-
'basePath' => '@mdm/admin/messages'
102-
];
103-
}
97+
// if (!isset(Yii::$app->i18n->translations['rbac-admin'])) {
98+
// Yii::$app->i18n->translations['rbac-admin'] = [
99+
// 'class' => 'yii\i18n\PhpMessageSource',
100+
// 'sourceLanguage' => 'en',
101+
// 'basePath' => '@mdm/admin/messages'
102+
// ];
103+
// }
104104
$userClass = ArrayHelper::getValue(Yii::$app->components, 'user.identityClass');
105105
if ($this->defaultRoute == 'default' && $userClass && is_subclass_of($userClass, 'yii\db\BaseActiveRecord')) {
106106
$this->defaultRoute = 'assignment';

components/ItemController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@ public function actionCreate()
8787
{
8888
$res = $this->auth_item_model->addPermission($this->type);
8989
Helper::invalidate();
90+
if ( !$res) {
91+
RbacHelper::error();
92+
}
9093
if ($this->type == 1) {
91-
if ( !$res) {
92-
RbacHelper::error();
93-
}
94-
9594
return ArrayHelper::toArray($res['_item']);
9695
}
9796

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"authors": [
1818
{
19-
"name": "new7",
19+
"name": "windhoney",
2020
"email": "[email protected]"
2121
}
2222
],

controllers/base/ApiController.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?php
2-
/**
3-
* 所有接口基类,授权验证,格式设定
4-
*
5-
* @author zhanghongwei
6-
*/
72

83
namespace wind\rest\controllers\base;
94

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

14+
/**
15+
* 所有接口基类,授权验证,格式设定
16+
*
17+
* @author windhoney
18+
* @package wind\rest\controllers\base
19+
*/
1920
class ApiController extends ActiveController
2021
{
2122

@@ -105,4 +106,4 @@ public function afterAction($action, $result)
105106

106107
return $this->serializeData($data);
107108
}
108-
}
109+
}

helper/RbacHelper.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
2-
/**
3-
* 公共方法
4-
*
5-
* @author zhanghongwei
6-
*/
72

83
namespace wind\rest\helper;
94

105
use yii\log\FileTarget;
116

7+
/**
8+
* 公共方法
9+
* @author windhoney
10+
* @package wind\rest\helper
11+
*/
1212
class RbacHelper
1313
{
1414

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

121121
return $main;
122122
}
123-
}
123+
}

models/AuthItem.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function rules()
6767
[['name', 'type'], 'required'],
6868
[
6969
['name'],
70-
'unique',
70+
'checkUnique',
7171
'when' => function () {
7272
return $this->isNewRecord || ($this->_item->name != $this->name);
7373
}
@@ -81,17 +81,12 @@ public function rules()
8181
/**
8282
* Check role is unique
8383
*/
84-
public function unique()
84+
public function checkUnique()
8585
{
8686
$authManager = Yii::$app->authManager;
8787
$value = $this->name;
8888
if ($authManager->getRole($value) !== null || $authManager->getPermission($value) !== null) {
89-
$message = Yii::t('yii', '{attribute} "{value}" has already been taken.');
90-
$params = [
91-
'attribute' => $this->getAttributeLabel('name'),
92-
'value' => $value,
93-
];
94-
$this->addError('name', Yii::$app->getI18n()->format($message, $params, Yii::$app->language));
89+
$this->addError('name');
9590
}
9691
}
9792

models/Blog.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)