简体   繁体   English

即使存在也找不到路由 php 叶框架

[英]route not found even if it exist php leaf framework

When I run the project on my localhost the routes work perfectly but when I export to shared hosting it keeps giving {"data": "Resource not found", "code":404} according to the 404 configurations in the Route/index.php当我在本地主机上运行项目时,路由运行良好,但是当我导出到共享主机时,它会根据路由/索引中的 404 配置不断给出 {"data": "Resource not found", "code":404}。 php

I've hosted a previous project using this framework and it still works to this moment, but I don't know what I'm doing wrong for this particular project.我已经使用这个框架托管了一个以前的项目,它至今仍然有效,但我不知道我在这个特定项目中做错了什么。 I've crossed checked the previous project config with this one and there's no difference.我已经用这个交叉检查了以前的项目配置,没有区别。

This is the content of my.env file这是 my.env 文件的内容

    APP_NAME=LEAF_API
    APP_ENV=local
    APP_KEY=base64:AUAyDriQD1kFdIbwTHlnCm2pYn+qxDBa55SFwB9PUzg=
    APP_DOWN=false
    APP_DEBUG=true
    APP_URL=http://localhost

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=9jafood
    DB_USERNAME=root
    DB_PASSWORD=
    DB_CHARSET=utf8
    DB_COLLATION=utf8_unicode_ci

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=null
    MAIL_PASSWORD=null
    MAIL_ENCRYPTION=null

    PROD_SERVER=hello
    PROD_PORT=22
    PROD_USER=leaf
    APPLICATION_DIR=leaf
    APPLICATION_PATH=leaf

This is my .htaccess file这是我的 .htaccess 文件

   <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
           Options -MultiViews -Indexes
        </IfModule>

        RewriteEngine On

        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]

        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>

This the index file that the .htaccess file rewrites to这是 .htaccess 文件重写的索引文件

  <?PHP

  require_once __DIR__ . '/vendor/autoload.php';

  \Dotenv\Dotenv::create(__DIR__)->load();

  require __DIR__ . "/Config/bootstrap.php";

  require __DIR__ . "/Config/functions.php";

  Leaf\View::attach(\Leaf\Blade::class);

  $app = new Leaf\App(AppConfig());

  $app->evadeCors(false);

  require __DIR__ . "/App/Routes/index.php";

  $app->run();

This is my index.php file located in the Route folder这是我位于 Route 文件夹中的 index.php 文件

    <?php

    /**@var Leaf\App $app */

    $app->set404(function () {
     json("Resource not found", 404, true);
    });

    $app->setErrorHandler(function ($e = null) use($app) {
     if ($e) {
      if ($app->config("log.enabled")) {
         $app->logger()->error($e);
      }
    }

    json("An error occured, our team has been notified", 500, true);
    });

    $app->setNamespace("\App\Controllers");

    require __DIR__ . "/_route.php";

This is my route.php这是我的路线。php

    <?php

       $app->group("/merchant", function () use ($app) {
       $app->post("/", "VendorsController@index");
       $app->get("/delivery/{id}", "VendorsController@cost");
       $app->get("/category/{id}", "CategoriesController@index");
   });

       $app->group("/meal", function () use ($app) {
       $app->get("/", "MealsController@index");
       $app->post("/search", "MealsController@search");
       $app->post("/search/location", "MealsController@searchBasedOnLocation");
   });

this might be really late considering the date, but I just noticed you are requiring a _route.php file but your file name looks like route.php .考虑到日期,这可能真的太晚了,但我只是注意到您需要一个_route.php文件,但您的文件名看起来像route.php

Also you can post your questions on the leaf forum on GitHub as well so they can be resolved quickly.您也可以在 GitHub 的叶子论坛上发布您的问题,以便快速解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM