Universal backend role permission management system, based on vue-element-admin and PHP CodeIgniter 3.1.10 RESTful implementation. It adopts a permission management system with front-end and back-end separation architecture and a PHP rapid development platform. The goal is to build a simple and easy-to-use rapid solution. It can help users effectively reduce project development difficulty and cost.
Based on the [email protected] front-end template, modify the dynamic routing part to realize that the menu routing can be dynamically loaded according to the back-end role. The back-end routing permissions are based on php-jwt
and use php CI hook
for token and permission authentication.
Except for the home page and documents, the original sample templates of the vue-element-admin front-end are archived under the样例模板
menu, see @router/index.js constantRouterMap, and other components such as tags-views, etc., are not done. Changes can be made and deleted based on specific needs.
For the implementation of dynamically switching roles, see vue-php-admin-V3
jwt token方式
, github/gitee 三方登录
gregwar/captcha
package), corporate WeChat scan code to log in, see vue-php-admin-V3 logs
table For a complete example of addition, deletion, modification and query of restful specifications, see Article.php controller
The catfan/medoo package database operation is introduced to replace part of the model of the CI framework. TODO: Use medoo to completely replace the CI database operation.
Use catfan/medoo to implement complex paging filtering and sorting. See article_get() and users_get() and vue front-end GET request construction parameters.
The front-end GET request parameters are related to the table component used. The vue-data-tables component is used here.
GET /articles?offset=1&limit=30&sort=-id&fields=id,title,author&query=~author,title&author=888&title=world
limit: 每页记录数,后台会配置默认值
offset: 第几页,后台会配置默认值
sort: 支持多个参数 &sort=-id,+author => id降序 author 升序
fileds: 指定要获取的显示字段 => 降低网络流量
query: 支持多个参数 &query=~author,title => author like 模糊查询, title精确查询 &author=888&title=world 需要配合query参数才有意义
Download the front-end code (vue-element-admin directory) and unzip it
Modify interface configuration
cat .env.development
# base api
VUE_APP_BASE_API = 'http://www.cirest.com:8890/api/v2/'
run
npm run dev
Download the PHP backend code (CodeIgniter-3.1.10 directory) and unzip it
Create the database vueadmin and import the vueadmin.sql file. When navcat-for-mysql import sometimes causes errors, modify the mysql my.ini configuration file parameter mysqld and add max_allowed_packet = 500M under the node.
Backend database connection configuration modification configuration file
cat applicationconfigdatabase.php
$ db [ ' default ' ] = array(
' dsn ' => '' ,
' hostname ' => ' localhost ' ,
' username ' => ' root ' ,
' password ' => ' root ' ,
' database ' => ' vueadminv2 ' ,
...
cat applicationconfigconfig.php
// medoodb 初始化数据库全局配置, 注意与CI databases.php 区别, TODO: 完全弃用 CI 自带数据库操作,使用medoodb
$ config [ ' medoodb ' ] = [
' database_type ' => ' mysql ' ,
' database_name ' => ' vueadminv2 ' ,
' server ' => ' localhost ' ,
' username ' => ' root ' ,
' password ' => ' root ' ,
' charset ' => ' utf8 ' ,
//可选:端口
' port ' => 3306 ,
//可选:表前缀
' prefix ' => '' ,
// PDO驱动选项 http://www.php.net/manual/en/pdo.setattribute.php
' option ' => [
PDO :: ATTR_CASE => PDO :: CASE_NATURAL
]
];
CodeIgniter-3.1.10 directory, composer installs related dependency packages php-jwt and codeigniter-restserver
composer install // 根据composer.json 初始安装所有插件包
Or manually
composer require chriskacerguis/codeigniter-restserver
composer require firebase/php-jwt
composer require league/oauth2-github
composer require nette/http
composer require catfan/medoo
Use phpstudy to configure site domain name management and modify the hosts file (optional)
www.cirest.com:8890 Note that it is consistent with the front-end interface configuration BASE_API: '"http://www.cirest.com:8890/api/v2/"'
API interface call usage example:
http://www.cirest.com:8890/api/v2/sys/user/testapi # 免token认证测试接口正常 对应 GET 请求
http://www.cirest.com:8890/index.php/api/v2/sys/user/testapi
The token-free authentication test interface is configured in CodeIgniter-3.1.10/config/config.php
$ config [ ' jwt_white_list ' ] = [
' /example/users/get ' ,
' /example/users/post ' ,
' /example/users/delete ' ,
' /article/articles/get ' , // 测试api接口不认证 http://www.cirest.com:8890/api/v2/article/articles uri_string => api/v2/article/articles
' /article/articles/post ' ,
' /article/articles/put ' ,
' /article/articles/delete ' ,
' /sys/user/testapi/get ' ,
]
The backend php interface uri contains index.php. If you want to remove and modify CodeIgniter-3.1.10/.htaccess
file (Apache) in the root directory, please note that it is not in CodeIgniter-3.1.10/application/
directory.
cat CodeIgniter-3.1.10/.htaccess
< IfModule mod_rewrite.c >
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?/$1 [QSA,PT,L]
</ IfModule >
For Nginx, you need to modify the corresponding configuration of nginx.
sys_perm
table. The super administrator role of the system automatically has all permissions (can also be designed according to specific business needs)Tables_in_vueadminv2 | illustrate |
---|---|
keys | PHP CI RESTful apikey can be turned on and off in config.php |
logs | PHP CI RESTful log table can be turned on and off in config.php |
sys_dept | System department table |
sys_menu | System menu table |
sys_perm | System permission table |
sys_perm_type | Permission type (not used yet) |
sys_role | System role table |
sys_role_perm | Role permission relationship table |
sys_user | System user table |
sys_user_dept | Table of departments to which users belong (can be one-to-many) |
sys_user_role | User role correspondence |
sys_user_token | Using JWT token this table is useless |
upload_tbl | Business test form |
php 7.3.4nts
+ Apache 2.4.39
CodeIgniter-3.1.10applicationconfigconfig.php // access_token/refresh_token
expiration time configuration
$config['jwt_access_token_exp'] = 15; // 单位秒
$config['jwt_refresh_token_exp'] = 180; // 单位秒