我试图在实体类中加载并在循环中使用,以便动态地从文件中将内容加载到相关表中。
是否可以从以下位置加载所有实体文件
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"? 即使在我当前是hrd编码的时候,也要使用stament调用
use AppBundle\Entity\abPostcode;发布于 2017-10-16 11:07:09
我解决了这个问题,方法是将该功能提取到帮助程序中,并根据输入运行一个开关语句--在本例中是{前缀}。
发布于 2017-10-15 14:02:10
如果不调用完整的命名空间,就无法动态实例化类。试一试:
$namespace = "AppBundle\Entity\\";
$entityName = "YourEntity";
$namespace .= $entityName;
$class = new $namespace();这是为我工作..。
发布于 2021-05-11 11:29:44
我遇到了这样的问题:将数据从一种数据库类型迁移到另一种数据库类型。IE:甲骨文转MySQL。有了数百张表,使用部分就会变大。
这是在Symfony 5.2.x BTW上。
当我使用标准存储库或链接到表的存储库运行查询时,我可以使用其完整的命名空间调用实体。
$oracle = $em2->getRepository(\App\Entity\Oracle\Appoints::class)->Appoints();因此,我不必加载“使用App\Entity\Oracle\Appoints”
然后,我可以以同样的方式创建一个新对象:
$mysqlObject = new \App\Entity\OracleAppPoints();https://stackoverflow.com/questions/46754646
复制相似问题