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条)

报告相同问题?