drxt70655 2017-10-15 11:45
浏览 63
已采纳

以编程方式在symfony中加载实体

I am trying to load in Entity classes and use within a loop in order to load content in dynamically from files into relating tables.

Is there any way i can load in all Entity files from the following

use AppBundle\Entity\aaPostcode;
use AppBundle\Entity\abPostcode;
use AppBundle\Entity\acPostcode;
use AppBundle\Entity\adPostcode;

in such a way like this?

use AppBundle\Entity\*

Not sure if this is possible in Symfony.

My next issue is using the the prefixedEntity within a loop like so -

new $entityPrefix

When i am setting $entityPrefix to the following format

$entityPrefix = str_replace([".csv"], "", $entityFilename) . "Postcode" . '()';

which returns the string of

"abPostcode()"

can anyone advise as to why calling

new $entityPrefix;

is not working

Thanks in advance for any help!

trying to call

new $entityPrefix();

returns

[Symfony\Component\Debug\Exception\ClassNotFoundException]           
Attempted to load class "abPostcode" from the global namespace.      
Did you forget a "use" statement for "AppBundle\Entity\abPostcode"?  

even when i current am hrd coding the use stament to call

use AppBundle\Entity\abPostcode;
  • 写回答

2条回答 默认 最新

  • douyao6842 2017-10-16 11:07
    关注

    I solved this by pulling out the functionality into a helper and running a switch statement based on the input - in this case a {prefix}

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问各位,如何在Jetson nano主控板的Ubuntu系统中安装PyQt5
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥150 求 《小魔指》街机游戏机整合模拟软件