$entityA1 = $entity_manager->getRepository(...)->find(1);
$entityA1->addEntitiesB(new EntityB());
$entityA2 = $entity_manager->getRepository(...)->find(1); // получаем новый объект (из базы)
$entitiesB = $entityA2->getEntitiesB(); // пусто
$entitiesB = $entityA1->getEntitiesB(); // а тут будет сохранённый объект
class DefaultController extends Controller {
public function showAction($login)
{
$human = $this->get("PeopleService")->getByLogin($login);
}
}
<?php
namespace AppBundle\DBAL;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
abstract class EnumType extends Type
{
protected $name;
public static $VALUES = array();
public static function getValues()
{
$values = array();
foreach (static::$VALUES as $value) $values[$value] = $value;
return $values;
}
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
$values = array();
foreach (static::$VALUES as $value) $values[] = "'$value'";
return "ENUM(".implode(", ", $values).") COMMENT '(DC2Type:$this->name)'";
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return $value;
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (!in_array($value, static::$VALUES)) {
throw new \InvalidArgumentException("Invalid value '$value' for enum '$this->name'.");
}
return $value;
}
public function getName()
{
return $this->name;
}
}
<?php
namespace AppBundle\DBAL;
class MyType extends EnumType
{
protected $name = 'mytype';
const FIRST = 'first';
const SECOND = 'second';
public static $VALUES = array(self::FIRST, self::SECOND);
}
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
types:
mytype: AppBundle\DBAL\MyType
mapping_types:
enum: string
class MyEntity
{
/**
* @var integer $id
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// ....
/**
* @var string
*
* @ORM\Column(type="mytype")
*/
protected $type;
class User
{
// ...
public function getFullDomain($template)
{
return str_replace("{subdomain}", $this->subdomain, $template);
}
}
$this->exist = $this->createQueryBuilder('i')
public function findByCategory($category)
{
$qb = clone($this->exist);
return $qb
->andWhere('i.category = :category')
->setParameter('category', $category)
->getQuery()->getResult();
}
->where('i.isActive = true')
{% for category in categories if category.items is not null %}
{{category.name}}
{% for item in category.items %}
- {{ item.name }}
{% endfor %}
{% endfor %}
<?php
namespace AppBundle\DBAL;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
abstract class EnumType extends Type
{
protected $name;
public static $VALUES = array();
public static function getValues()
{
return array_combine(static::$VALUES, static::$VALUES);
}
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
$values = array_map(function($val) { return "'".$val."'"; }, static::$VALUES);
return "ENUM(".implode(", ", $values).") COMMENT '(DC2Type:".$this->name.")'";
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return $value;
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (!in_array($value, static::$VALUES)) {
throw new \InvalidArgumentException("Invalid value '$value' for enum '$this->name'.");
}
return $value;
}
public function getName()
{
return $this->name;
}
}
<?php
namespace AppBundle\DBAL;
class GenderType extends EnumType
{
protected $name = 'gender';
public static $VALUES = array('male', 'female');
}
doctrine:
dbal:
# ...
types:
gender: AppBundle\DBAL\GenderType
mapping_types:
enum: string
gender: gender
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
*/
class Person
{
// other fields
/**
* @var string
*
* @ORM\Column(type="gender")
*/
protected $gender;
// setters & getters
}
foreach (GenderType::$VALUES as $gender) {
echo $gender;
}
$form = $this->createForm(new SignInForm(), null, array(
'action' => $this->generateUrl('login_check'),
'method' => 'POST',
));
$form = $this->createForm(new SignInForm());
namespace YourBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class User
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $lastName;
/**
* @ORM\Column(type="string", length=100)
*/
private $username = "";
/**
* @ORM\Column(type="string", length=100, unique=true)
*/
private $email;
/**
* @ORM\Column(type="string", length=100)
*/
private $password;
// getters & setters
}