Skip to content
Advertisement

Programmatically load Entity in 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 AppBundleEntityaaPostcode;
use AppBundleEntityabPostcode;
use AppBundleEntityacPostcode;
use AppBundleEntityadPostcode;

in such a way like this?

use AppBundleEntity*

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

[SymfonyComponentDebugExceptionClassNotFoundException]           
Attempted to load class "abPostcode" from the global namespace.      
Did you forget a "use" statement for "AppBundleEntityabPostcode"?  

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

use AppBundleEntityabPostcode;

Advertisement

Answer

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}

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement