Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
王兴勇
/
helper-config
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2ddd701a
authored
Oct 26, 2017
by
王兴勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
创建帮助文档
parent
4bb2190a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
README.MD
+57
-0
No files found.
README.MD
0 → 100644
View file @
2ddd701a
#快捷功能
###功能
1.
模拟会员登陆
2.
模拟Admin后台登陆
3.
快捷切换数据连接
###警告
以下所有配置文件名不能出现 . 这个符号,如果文件名出现 . 这个符号会被转成对应的目录分隔符 /
###模块引入
在
`shopnc.php`
头部
```
php
require
sprintf
(
'%s%sconfig%2$scommon.php'
,
dirname
(
__DIR__
),
DIRECTORY_SEPARATOR
);
```
###数据库快捷切换功能
修改
`data/config/config.ini.php`
中修改 mysql 配置参数
```
php
...
$config
[
'db'
][
'master'
][
'dbhost'
]
=
$__DB_CONFIG
[
'dbhost'
];
$config
[
'db'
][
'master'
][
'dbport'
]
=
isset
(
$__DB_CONFIG
[
'dbport'
])
?
$__DB_CONFIG
[
'dbport'
]
:
'3306'
;
$config
[
'db'
][
'master'
][
'dbuser'
]
=
$__DB_CONFIG
[
'dbuser'
];
$config
[
'db'
][
'master'
][
'dbpwd'
]
=
$__DB_CONFIG
[
'dbpwd'
];
$config
[
'db'
][
'master'
][
'dbname'
]
=
$__DB_CONFIG
[
'dbname'
];
...
```
使用
`require_db_config`
来实现数据库连接快速切换
个人在
`shopnc.php`
引入功能文件后使用
`require_db_config`
```
php
/**
* @param string $config_name 数据库配置名称
* @info 数据库配置文件统一存入在 db 目录中
* @demo require_db_config('local'); //会加载 db 目录下的 local.php
*/
$__DB_CONFIG
=
require_db_config
(
$config_name
);
```
#####以下一断是为了兼容命令行模式执行PHP时使用,不使用命令行可忽略
```
php
//在 config.ini.php 文件头部写入以下代码
if
(
!
function_exists
(
'local'
))
{
$path
=
dirname
(
dirname
(
dirname
(
__DIR__
)));
require
sprintf
(
'%s%sconfig%2$scommon.php'
,
$path
,
DIRECTORY_SEPARATOR
);
$__DB_CONFIG
=
require_db_config
(
'local'
);
}
```
###用户模拟登陆
使用
`faker_login`
来实现数据库连接快速切换
个人在
`shopnc.php`
底部使用
`faker_login`
```
php
/**
* @param string $configs 要模拟的用户
* @info 可以同登陆一个会员与Admin后台 会员同一请求只能使用一个
* @demo faker_login('170'); //会模拟登陆重庆飞耀
* @demo faker_login('170,admin'); //会同时模拟登陆重庆飞耀与admin后台
*/
faker_login
(
$configs
);
```
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment