douye9822 2019-02-28 16:19
浏览 44

子目录中路由的Slim 3问题

I have an app with the following structure:

App/
|— app/
    |— config
    |— controllers
    |— middlewares
    |— routes
         |— routes.php
    |— views
    |— app.php
    |— autoload.php
|— public/
    |—.htaccess
    |— index.php
|— vendor/

Ok, in the .htaccess on the /public folder contain the following (from the Slim docs):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

And the index.php on the /public folder contain the following:

define('BASE_ROOT',dirname(__DIR__) . '/');
require_once BASE_ROOT.'app/app.php';
$app->run();

So, we go to the app/app.php file:

<?php
require BASE_ROOT.'app/autoload.php';

$app = new \Slim\App(["settings" => App\Config\Config::$config]); 

$container = $app->getContainer(); 
$container['view'] = function($container) {
  /*Set some configurations and environment vars*/
};

require BASE_ROOT.'app/routes/routes.php';

And finally, in the routes.php inside on app/routes/:

<?php

/*Routes*/
$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
  $name = $args['name'];
  $response->getBody()->write("Hello, $name");
});

I've put the 'hello world' route to simplify things, but the problem is that with any route registered in routes.php I receive 404 code...

I'm using apache server and the configuration on vhost is the following:

<VirtualHost *:80>
    DocumentRoot "C:\Users\FranciscoSalazar\Desktop\PHP-SLIM\App\public"
    ServerName medo
    <Directory C:\Users\FranciscoSalazar\Desktop\PHP-SLIM\App\public>
        DirectoryIndex index.php
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
I use:
 - PHP 7.3.2
 - Slim 3.0
 - Apache 2.4

If someone knows the answer or can guide me, I will appreciate it very much.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line