index.php 1.6 KB

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