12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- use Qii\Base\Route;
- require_once('../../src/Qii.php');
- //composer安装的将上边那行 require_once('../../src/Qii.php'); 换成 require("../../vendor/autoload.php");
- $app = \Qii::getInstance();
- //程序所在目录,不用暴露在外网上
- $app->setWorkspace('../private');
- //临时文件写入目录
- $app->setCachePath('tmp');
- //app相关配置
- $app->setAppConfigure('configure/app.ini');
- //设置指定前缀是否使用namespace,仅限于使用框架本省的autoload
- $app->setUseNamespace('Bootstrap', false);
- //设置logger,用于错误日志收集
- $app->setLogger('plugins\logger');
- //设置数据库配置文件
- $app->setDB('configure/db.ini');
- //设置路由
- Route::prefix("/admin")->setMiddleware(['\middleware\admin'])->group(function($route){
- $route->get("/user/login", function(){return "admin";});
- $route->get('/book/info', function(){return 'book/info';});
- $route->get('/profile/edit', ['admin\profile\edit', 'index']);
- $route->put('/user/add', 'admin\user\add');
- });
- Route::prefix("/user")->setMiddleware(['\middleware\auth'])->group(function($route) {
- $route->get('/profile', function(){return 'login first';});
- $route->get('/index', function(){return 'this is user center';});
- });
- //或者从目录中加载
- $app->loadRouteFromPath('../private/configure/route');
- //设置路由规则
- $app->setRouter('configure/router.config.php');
- //设置启动执行的代码,可以用于初始化需要用到的东西
- $app->setBootstrap();
- //设置全局中间件
- $app->setGlobalMiddleware(['\middleware\site']);
- //运行
- $app->run();
|