PHP code example of adrenalinkin / entity-helper-bundle
1. Go to this page and download the library: Download adrenalinkin/entity-helper-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adrenalinkin / entity-helper-bundle example snippets
// app/AppKernel.php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
/**
* The Kernel is the heart of the Symfony system
*/
class AppKernel extends Kernel
{
/**
* {@inheritdoc}
*/
public function registerBundles()
{
$bundles = [
// ...
new Linkin\Bundle\EntityHelperBundle\LinkinEntityHelperBundle(),
];
return $bundles;
}
/**
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
// ...
/** @var \Symfony\Component\DependencyInjection\ContainerInterface $container */
$entityHelper = $container->get('linkin_entity_helper.helper');
// Create empty User entity
$user = $entityHelper->createEntity(User::class);
// Create empty User entity by received short name
$user = $entityHelper->createEntity('AcmeBundle:User');
// Create User entity and fill some fields
$user = $entityHelper->createEntity('AcmeBundle:User', ['id' => 1, 'username' => 'acme-login']);
// Create User entity and fill identity field in that case when you don't know the name of the identity field
foreach (['AcmeBundle:User', 'AcmeBundle:Role'] as $className) {
$object = $entityHelper->createEntity($className, [EntityHelper::IDENTITY => 1]);
}