PhpStorm 2024.1 Help

Live templates for Symfony

Live templates are code snippets for the frequently used code constructs that PhpStorm inserts automatically as you type a corresponding template name. Symfony live templates reference contains the full list of live templates for Symfony components in PhpStorm.

To have PhpStorm insert the code snippet for you, type the live template name (in code completion suggestions, templates are marked with ) and press Tab. To navigate from one variable in the inserted template to another, press Tab and Shift+Tab.

Adding Symfony live templates

To edit the IDE's pre-configured Symfony live templates or create a custom one, go to Settings  (Ctrl+Alt+S) | Editor | Live Templates and expand the Symfony node.

Symfony live templates settings

Symfony live templates reference

Template name

Template text

404unless
if ($CONDITION$) { throw $this->createNotFoundException($MESSAGE$); }
action
#[Route(path: '/$PATH$', name: '$ROUTE_NAME$')] public function $NAME$Action() { $END$ }
add
->add('$FIELD$', $CLASSNAME$::class)
addflash
$this->addFlash('$TYPE$','$MESSAGE$');
choice
#[Assert\Choice(choices: ['$CHOICE$'])]
column
#[ORM\Column(name: '$NAME$', type: '$TYPE$', length: $LENGTH$)]
command
namespace $NAMESPACE$; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand(name: '$COMMANDNAME$', description: '$DESCRIPTION$')] class $CLASSNAME$ extends Command { protected function configure(): void { $TODO$ } protected function execute(InputInterface $input, OutputInterface $output): int { return Command::SUCCESS; } }
controller
namespace $NAMESPACE$; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; class $CLASSNAME$ extends AbstractController { #[Route(path: '/$PATH$', name: '$NAME$')] public function someAction($name) { $END$ } }
createquery
$this->getEntityManager() ->createQuery('SELECT $ALIAS$ FROM $ENTITY$ $ALIAS$ WHERE $ALIAS$.$PROPERTY$ = :$PARAMETER$') ->setParameter('$PARAMETER$', $ARGUMENT$) ->execute();
discriminatorcolumn
#[ORM\DiscriminatorColumn(name: '$NAME$', type: '$TYPE$')]
discriminatormap
#[ORM\DiscriminatorMap(['$VALUE$' => $CLASSNAME$::class])]
doctrinecolumn
/** @var $PHPTYPE$ */ #[ORM\Column(name: '$FIELDNAME$', type: '$TYPE$')] private $$$PROPERTYNAME$;
email
#[Assert\Email(message: '$MESSAGE$')]
embeddable
#[ORM\Embeddable]
embedded
#[ORM\Embedded(columnPrefix: '$PREFIX$', class: $ENTITY$::class)]
entity
namespace $NAMESPACE$; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] #[ORM\Table(name: '$NAME$')] class $CLASSNAME$ { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: 'int')] private int $id = 0; public function getId(): int { return $this->id; } }
entityattribute
#[ORM\Entity(repositoryClass: $REPOSITORY$::class)]
formbuilder
$formBuilder = $this->createFormBuilder(); return $formBuilder ->add('$FIELD$', $CLASSNAME$::class)$END$;
formhandle
$form = $this->createForm($CLASSNAME$::class); $form->handleRequest($REQUEST$); if ($form->isSubmitted() && $form->isValid()) { $END$ }
getem
$EM$ = $this->getDoctrine()->getManager();
getrepo
$EM$->getRepository('$ENTITY$');
groups
#[Groups(groups: ['$GROUP$'])]
id
#[ORM\Id]
ignore
#[Ignore]
index
#[ORM\Index(name: '$NAME$', columns: [$COLUMNS$])]
joincolumn
#[ORM\JoinColumn(name: '$NAME$', referencedColumnName: '$REFERENCE$', onDelete: '$DELETE$')]
jointable
#[ORM\JoinTable(name: '$NAME$')]
length
#[Assert\Length(min: $MIN$, max: $MAX$)]
manytomany
#[ORM\ManyToMany(targetEntity: '$TARGET$')]
manytoone
#[ORM\ManyToOne(targetEntity: '$TARGET$')]
notBlank
#[Assert\NotBlank(allowNull: $ALLOWNULL$)]
notNull
#[Assert\NotNull]
onetomany
#[ORM\OneToMany(targetEntity: '$TARGET$')]
onetoone
#[ORM\OneToOne(targetEntity: '$TARGET$')]
persistflush
$EM$->persist($ENTITY$); $EM2$->flush();
querybuilder
$QB$ = $this->createQueryBuilder('p') ->where('p.$PROPERTY$ = :$PARAMETER$') ->setParameter('$PARAM$', $ARGUMENT$) ->getQuery();
redirect
return $this->redirect('$URL$');
removeflush
$EM$->remove($ENTITY$); $EM2$->flush();
rendertwig
return $this->render('$TEMPLATE$.html.twig', [ $VAL$ ]);
repofind
$VAR$ = $this->getDoctrine() ->getRepository('$REPO$') ->$METHOD$($ARG$);
required
#[Required]
route
#[Route(path: '/$PATH$', name: '$NAME$', methods: ['$METHOD$'])]
serializedName
#[SerializedName(serializedName: '$NAME$')]
table
#[ORM\Table(name: '$NAME$')]
type
#[Assert\Type(type: '$TYPE$')]
uniqueEntity
#[UniqueEntity(fields: ['$FIELD$'])]
uniqueconstraint
#[ORM\UniqueConstraint(name: '$NAME$', columns: [$COLUMNS$])]
valid
#[Assert\Valid]
Last modified: 26 May 2024