index.php 1.6 KB

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