Laravel,没有外壳访问的转储自动加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26109816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:12:16  来源:igfitidea点击:

Laravel, dump-autoload without Shell Access

phpshelllaravellaravel-4composer-php

提问by Justin

I have two controllers with the same name:

我有两个同名的控制器:

app\controllers\CareersController.php(for public use) app\controllers\Admin\CareersController.php(for admins)

app\controllers\CareersController.php(供公众使用) app\controllers\Admin\CareersController.php(供管理员使用)

Because of the naming conflict, I added namespace admin;to the admin controller.

由于命名冲突,我添加namespace admin;到admin控制器。

Everything works fine locally but when I uploaded the new admin controller to my server, I get an error: Class Admin\CareersController does not exist

本地一切正常,但是当我将新的管理控制器上传到我的服务器时,出现错误: Class Admin\CareersController does not exist

From what I understand, the fix is: php artisan dump-autoloadand composer dump-autoload

据我了解,该修补程序是: php artisan dump-autoloadcomposer dump-autoload

However, I don't have Shell access to run those commands and composer isn't installed on the server anyway. So, is there a way to reload the auto-load file without Shell access?

但是,我没有运行这些命令的 Shell 访问权限,并且无论如何都没有在服务器上安装 Composer。那么,有没有办法在没有 Shell 访问的情况下重新加载自动加载文件?

采纳答案by Laurence

You dont need shell access. Artisan includes a dump-autoloadfunction. You can just it via a PHP call within your app:

您不需要外壳访问。Artisan 包含一个dump-autoload函数。您可以通过应用程序中的 PHP 调用来实现:

Route::get('/updateapp', function()
{
    \Artisan::call('dump-autoload');
    echo 'dump-autoload complete';
});

Edit: just noticed you wrote "composer isn't installed on the server anyway". Not sure what will happen - try the command above and let us know.

编辑:刚刚注意到您写道“无论如何都没有在服务器上安装作曲家”。不确定会发生什么 - 尝试上面的命令并告诉我们。

If it doesnt work - then just run composer dump-autoload locally - then upload your new autoload.php.

如果它不起作用 - 那么只需在本地运行 composer dump-autoload - 然后上传您的新 autoload.php。

As a side point - is there any option to switch servers? You going to keep running into various issues if you dont have command line & composer access. You could just use Forge and spin up a new server on DigitalOcean, Linode etc in less time than it would take to fix this issue :)

作为一个侧面 - 是否有任何切换服务器的选项?如果您没有命令行和作曲家访问权限,您将继续遇到各种问题。您可以使用 Forge 并在比解决此问题所需的时间更短的时间内在 DigitalOcean、Linode 等上启动新服务器:)

回答by user10971804

Run composer dump-autoloadlocally. Then, in your hosting site, you can update two files, autoload_classmap.phpand autoload_static.php, manually in vendor/composer folder. I prefer to copy and paste the added classes from local to the hosting server.

composer dump-autoload本地运行。然后,在您的托管站点中,您可以在 vendor/composer 文件夹中手动更新两个文件autoload_classmap.phpautoload_static.php。我更喜欢将添加的类从本地复制并粘贴到托管服务器。

回答by mohas

I was using a shared hosting by client's requirements and did not have access to ssh or composer, what I did was to composer dump-autoloadon my local machine and then I figured that for my project autoloader just updates composerdirectory in my vendordirectory, so I just re-uploaded that one folder after each dump-autoloadand not all vendor directory

我根据客户的要求使用共享主机,但无法访问 ssh 或 composer,我所做的是composer dump-autoload在本地机器上,然后我认为对于我的项目自动加载器只是更新composervendor目录中的目录,所以我只是重新上传每个dump-autoload而不是所有供应商目录之后的那个文件夹

Edit:

编辑:

Another pitfall for me that generated the same error but the cause was something else, I develop on Windows machine in which file and directory names are case insensitive when deploying to Linux server, the framework could actually not find my controllers so I changed

另一个陷阱对我来说产生了同样的错误,但原因是别的,我在 Windows 机器上开发,其中文件和目录名称在部署到 Linux 服务器时不区分大小写,框架实际上找不到我的控制器所以我改变了

Route::get('/news', 'newsController@index');

Route::get('/news', 'newsController@index');

to

Route::get('/news', 'NewsController@index');

Route::get('/news', 'NewsController@index');

now it is working, autoload is doing it's job correctly

现在它正在工作,自动加载正在正确地完成它的工作