您请求了一项不存在的服务 "phpexcel"

You have requested a non-existent service "phpexcel"

我知道有些问题几乎相同,但 none 似乎是我的问题。

我有一个 symfony 2.8.3 项目,它从 excel 文件读取数据并将其导入 mysql 数据库。它在本地主机上运行良好,但在过去的 48 小时内,我一直在尝试让它在我的服务器上运行。它是共享主机,无法通过 SSH 访问 linux。

当我尝试从服务器加载它时出现此错误:"You have requested a non-existent service "phpexcel"."

您似乎想使用来自 ExcelBundle 的服务。但是那个包没有加载。检查您是否已将其添加到生产环境中。

$bundles = array(
    // ...
    new Liuggio\ExcelBundle\LiuggioExcelBundle(),
);

不要忘记在任何配置(AppKernel.php 也)更改后清除生产环境中的缓存。

清除缓存 运行 php app/console cache:clear。您还可以添加环境参数:--env=dev--env=prod - 取决于您的环境。如果它没有帮助,那么只需删除 app/cache/ 目录的所有内容(或者 var/cache/ 如果是 Symfony3 应用程序)

Pawel 回答正确,但缺少一些东西:将此行:new Liuggio\ExcelBundle\LiuggioExcelBundle(), 添加到 AppKernel.php 文件后,在 $bundles 数组中,不要忘记清除缓存:如果您处于开发者模式,则从 app/cache/dev 删除文件;如果处于生产模式,则从 app/cache/prod 删除文件。