项目应用(一)基础结构
这些都是基础的,没有复杂的功能
为方便调试加入了[symfony debug](https://symfony.com/doc/current/components/debug.html)组件
# env文件加载使用了[symfony Dotenv](https://symfony.com/doc/current/components/dotenv.html)组件
# 新建.env文件,该文件以供版本追踪
.env|
APP_ENV=local
APP_DEBUG=true
# 新建本地.env文件,该文件加入版本忽略,和.env文件结构一样
.env|
APP_ENV=local
APP_DEBUG=true
# config目录下新建config.php文件,该文件以供版本追踪
config/config.php
<?php
return [
];
# config目录下新建config.local.php文件,该文件为实际应用配置,并加入版本忽略,和config.php结构一样
config/config.local.php
<?php
return [
];
# src目录新建Controller目录
# Controller目录新建Index.php(如有需要可以加上Controller,IndexController.php)
# Index.php
<?php
namespace App\Controller;
use Psr\Container\ContainerInterface;
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
/**
* @author akio <medue8@gmail.com>
* Class IndexController
* @package App\Controller
*/
class Index
{
/**
* @author akio <medue8@gmail.com>
* @var ContainerInterface
*/
protected $container;
/**
* IndexController constructor.
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* @author akio <medue8@gmail.com>
* @param Request $request
* @param Response $response
* @param array $args
* @return Response
*/
public function index(Request $request, Response $response, array $args)
{
echo __METHOD__;
return $response;
}
}
# 注册命名空间
composer.json
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
# config目录新增router.php
router.php
<?php
/** @var $app \Slim\App */
// $app
$app->get('/', \App\Controller\Index::class.':index');
http://slim.my/
GET
code