42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
namespace app\common\behavior;
|
|
|
|
class InitHook {
|
|
|
|
public function run(&$request) {
|
|
//未安装时不执行
|
|
if (substr(request()->pathinfo(), 0, 7) != 'install' && is_file(APP_PATH . 'database.php')) {
|
|
//初始化某些配置信息
|
|
if (cache('db_config_data')) {
|
|
\think\Config::set(cache('db_config_data'));
|
|
} else {
|
|
$config = model('common/Config');
|
|
\think\Config::set($config->lists());
|
|
}
|
|
|
|
//设置模型内容路由
|
|
//$this->setRoute();
|
|
}
|
|
}
|
|
|
|
|
|
protected function setRoute() {
|
|
$list = db('Rewrite')->select();
|
|
// foreach ($list as $key => $value) {
|
|
// $route[$value['rule']] = $value['url'];
|
|
// }
|
|
|
|
//模型类路由配置
|
|
$list = db('Model')->column('id,name', 'id');
|
|
|
|
foreach ($list as $key => $value) {
|
|
$route["admin/" . $value . "/index"] = "admin/content/index?model_id=" . $key;
|
|
$route["admin/" . $value . "/add"] = "admin/content/add?model_id=" . $key;
|
|
$route["admin/" . $value . "/edit"] = "admin/content/edit?model_id=" . $key;
|
|
$route["admin/" . $value . "/del"] = "admin/content/del?model_id=" . $key;
|
|
$route["admin/" . $value . "/status"] = "admin/content/status?model_id=" . $key;
|
|
}
|
|
|
|
\think\Route::rule($route);
|
|
}
|
|
} |