【发布时间】:2018-03-27 01:11:42
【问题描述】:
我正在尝试加载实体类并在循环中使用,以便将内容从文件动态加载到相关表中。
有什么方法可以从以下加载所有实体文件
use AppBundle\Entity\aaPostcode;
use AppBundle\Entity\abPostcode;
use AppBundle\Entity\acPostcode;
use AppBundle\Entity\adPostcode;
以这样的方式?
use AppBundle\Entity\*
不确定这在 Symfony 中是否可行。
我的下一个问题是在这样的循环中使用 prefixedEntity -
new $entityPrefix
当我将 $entityPrefix 设置为以下格式时
$entityPrefix = str_replace([".csv"], "", $entityFilename) . "Postcode" . '()';
返回字符串的
"abPostcode()"
谁能告诉我为什么打电话
new $entityPrefix;
不工作
提前感谢您的帮助!
试图打电话
new $entityPrefix();
返回
[Symfony\Component\Debug\Exception\ClassNotFoundException]
Attempted to load class "abPostcode" from the global namespace.
Did you forget a "use" statement for "AppBundle\Entity\abPostcode"?
即使我现在是人力资源部编码的使用语句来调用
use AppBundle\Entity\abPostcode;
【问题讨论】:
-
你可以试试
$entityPrefix = 'abPostcode';然后new $entityPrefix(); -
感谢@kunicmarko20 已尝试此操作,但仍返回以下错误
-
有问题的错误
-
你不能这样做
use AppBundle\Entity\*。我建议只加载适当的类$entityPrefix = "AppBundle\Entity\" . str_replace([".csv"], "", $entityFilename) . "Postcode";
标签: php symfony doctrine schema