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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置