PHP code example of jinxing / yii2-admin
1. Go to this page and download the library: Download jinxing/yii2-admin library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jinxing / yii2-admin example snippets
return [
'modules' => [
'admin' => [
'class' => 'jinxing\admin\Module',
// 使用的登录用户组件
'user' => 'admin',
// 配置退出登录地址
'logoutUrl' => 'default/logout', // 默认就是default/logout
// 验证码验证地址
'captchaAction' => 'default/captcha', // 默认值为null 使用的就是default/captcha
]
],
'components' => [
// 后台登录用户组件信息
'admin' => [
'class' => 'yii\web\User',
'identityClass' => 'jinxing\admin\models\Admin',
'enableAutoLogin' => true,
'loginUrl' => ['/admin/admin/default/login'],
'idParam' => '_adminId',
'identityCookie' => ['name' => '_admin', 'httpOnly' => true],
],
// 后台使用的语言配置信息
'i18n' => [
'translations' => [
'admin' => [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en',
'basePath' => '@jinxing/admin/messages'
],
],
],
// 配置权限使用数据库
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
]
];
return [
// 这个配置是为了导入权限信息需要配置的,就是配置后台模块的路径
'admin_rule_prefix' => 'admin',
// 登录成功首页是否需要显示其他信息
'projectOpenOther' => true,
// 项目信息
'projectName' => 'Yii2 后台管理系统',
'projectTitle' => 'Yii2 后台管理系统',
'companyName' => '<span class="blue bolder"> Liujinxing </span> Yii2 Admin 项目 © 2016-2018',
];
return [
'components' => [
// 权限配置
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
],
];
namespace backend\controllers;
use jinxing\admin\behaviors\Logging;
use jinxing\admin\controllers\Controller as BaseController;
use yii\filters\AccessControl;
/**
* Class Controller 后台的基础控制器
* @package backend\controllers
*/
class Controller extends BaseController
{
/**
* @var string 使用 yii2-admin 的布局
*/
public $layout = '@jinxing/admin/views/layouts/main';
/**
* @var string 使用自己定义的上传文件处理表单
*/
public $uploadFromClass = 'backend\models\forms\UploadForm';
/**
* 定义使用的行为
*
* @return array
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'permissions' => [$this->action->getUniqueId()],
],
],
],
'logging' => [
'class' => Logging::className(),
],
];
}
}
namespace app\modules\admin;
use Yii;
use jinxing\admin\Module;
/**
* admin module definition class
*/
class Admin extends Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'app\modules\admin\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
Yii::$app->errorHandler->errorAction = $this->getUniqueId() . '/admin/default/error';
}
}
php yii migrate --migrationPath=@yii/rbac/migrations
php yii migrate --migrationPath=@jinxing/admin/migrations
// 登录地址、域名需要根据你的域名修改
http://localhost/path/to?index.php?r=admin/default/login