php - PHP,Laravel,未找到特征
问题描述
更新
经过太多次试验和失败后,我注意到这个错误有点误导。我回到旧版本之一,抓取旧文件并一一引入新版本。事实证明,当我更改 Publishings.php 时引发了错误,这与错误消息中提到的不同。
更新 2
这两个特征 Posts.php 和 Publishings.php 相互使用。我认为这会产生某种冲突。当我断开链接时,一切都恢复了。
原帖
我遇到了我遇到过的最奇怪的错误。我希望有人能帮帮忙。我有一堆特质,而且都互相使用。
/app
/Traits
/Products.php
/Publishings.php
/Posts.php
/...
Publishings.php 用于 5 个控制器和 2 个特征并且工作正常。但只有一个特征,它给出了这个错误:
Symfony\Component\ErrorHandler\Error\FatalError
Trait "App\Traits\Publishings" not found
引发错误的特征是 Posts.php:
<?php
namespace App\Traits;
use App\Models\Post;
use App\Models\Publishing;
use App\Traits\Pictures;
use App\Traits\Publishings;
use App\Traits\Videos;
use Carbon\Carbon;
trait Posts
{
use Pictures, Publishings, Videos;
public function...
}
错误来自第 12 行。该行的内容是“trait Posts”。
HomeController 也使用 Publishings 特征,当我删除使用 App\Traits\Publishings 时,它给了我未定义的函数错误。所以 HomeController 可以找到 Publishings。
我多次尝试清除所有缓存。没有帮助。此外,此应用程序的副本正在共享主机中运行,没有任何问题。我昨天重新安装了 Windows 10 的新副本,我的文件夹结构有点奇怪。即使我看不到任何关系,但我想知道我的问题是否与此有关。
C:\Coding\Projects // this is the document root instead of htdocs
C:\Coding\Platforms\Xampp
我没有主意了。任何帮助将不胜感激。提前致谢。
编辑:
这是 Publishings.php 的命名空间
<?php
namespace App\Traits;
use Illuminate\Support\Str;
use Carbon\Carbon;
use App\Models\Publishing;
use App\Traits\Pictures;
use App\Traits\Paginate;
use App\Traits\Videos;
use App\Traits\Specs;
use App\Traits\Posts;
trait Publishings
{
use Posts, Pictures, Paginate, Specs, Videos;
}
解决方案
文件夹结构无关紧要。如果您在命名空间中打错字,只要您在其他文件中使用相同的错字,它仍然可以工作。仔细检查命名空间。
你说:
HomeController 也使用 Publishings 特征,当我删除使用 App\Trait\Publishings 时,它给了我未定义的函数错误。所以 HomeController 可以找到 Publishings。
App\Trait\Publishings
不一样App\Traits\Publishings
!!!
推荐阅读
- php - 为什么 php 有时只有一个专门的函数来设置 ini 参数?
- powershell - 如何将命令行参数发送到从 PowerShell 脚本调用的程序?
- powershell - PowerShell 找不到类型
- python - 为什么安装 Cryptography python 包失败?
- huawei-mobile-services - HMS Core SDK集成测试找不到appid和cpid怎么办?
- mql4 - 在 MQL4 中放置一个指标和带有仅指标功能的 EA
- 3d - QGIS / GRASS GIS 如何使用 Z 值制作偏移/平行线
- ruby-on-rails-6 - 在 Rails 6 中更改文件后 Active Model Serializer 自动重新加载的问题
- javascript - 使用 Puppeteer 获取所有 href
- c++ - 如何将值从非 const 向量复制到 C++ 中的 const 向量?