dongxian7471
2019-02-16 13:51如何使用slim Framework分离不同目录中的不同路由
I am having some issues setting up routes in my app in different directories. The app only loads one of the routes files.
File Structure
myapp
|_public
| |_vendor
| |_index.php
|_src
|_routes
|_books.php
|_customers.php
index.php
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require './vendor/autoload.php';
$app = new \Slim\App;
// Routes
require '../src/routes/books.php';
require '../src/routes/customers.php';
$app->run();
customers.php
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
$app->get('/api/customers', function(Request $request, Response $response){
echo 'Customers';
});
books.php
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
$app->get('/api/books', function(Request $request, Response $response){
echo 'Books';
});
So with the above structure, only one on the routes file is loaded depending on the order in the file structure. Either the book routes or the customer routes and the order will return a Page not Found Error.
I don't understand.T
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 如何使用slim Framework分离不同目录中的不同路由
- php
- 1个回答