This is a Sublime Text package which includes handy snippets for doing Symfony2 framework development.
If you have the Package Control package installed, you can install Symfony2 Snippets from inside Sublime Text itself. Open the Command Palette and select "Package Control: Install Package", then search for Symfony2 Snippets.
If you haven't got Package Control installed you will need to make a clone of this repository into your packages folder, like so:
git clone https://github.com/raulfraile/sublime-symfony2 symfony2-snippets
All shortcuts start with the sf
prefix and are both short and intuitive:
sfcontroller
namespace VendorName\Bundle\BundleNameBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class ControllerNameController extends Controller
{
public function indexAction()
{
return $this->render('VendorNameBundleNameBundle:ControllerName:index.html.twig');
}
}
sfcontrollera
namespace VendorName\Bundle\BundleNameBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class ControllerNameController extends Controller
{
/**
* @Route(route configuration)
* @Template
*/
public function indexAction()
{
}
}
sfaction
public function indexAction()
{
return $this->render('BundleNameBundle:ControllerName:index.html.twig');
}
sfactiona
/**
* @Route(route configuration)
* @Template()
*/
public function indexAction()
{
}
sfem
$em = $this->getDoctrine()->getEntityManager();
sfrepo
$em->getRepository('Bundle:Repository');
sfforward
$this->forward('TestBundle:Folder:view', array());
sfredirect
$this->redirect($this->generateUrl('route'));
sfrender
$this->render('TestBundle:Folder:view.html.twig', array());
sfsession
$this->getRequest()->getSession();
sfsetflash
this->get('session')->setFlash('notice', 'message');
sfform
namespace VendorName\Bundle\BundleNameBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class FormNameType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'VendorName\\Bundle\\BundleNameBundle\\Entity\\FormName',
);
}
public function getName()
{
return 'formName';
}
}
sfdatatransformer
namespace VendorName\Bundle\BundleNameBundle\Form\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\TransformationFailedException;
class TransformerNameTransformer implements DataTransformerInterface
{
/**
* Transforms a value from the original representation to a transformed representation.
*
* @param mixed $value The value in the original representation
*
* @return mixed The value in the transformed representation
*
* @throws UnexpectedTypeException when the argument is not a string
* @throws TransformationFailedException when the transformation fails
*/
public function transform($value)
{
}
/**
* Transforms a value from the transformed representation to its original
* representation.
*
* @param mixed $value The value in the transformed representation
*
* @return mixed The value in the original representation
*
* @throws UnexpectedTypeException when the argument is not of the expected type
* @throws TransformationFailedException when the transformation fails
*/
public function reverseTransform($value)
{
}
}
sfentity
**
* @ORM\Entity
* @ORM\Table(name="name")
*/
sfentityClass
namespace VendorName\BundleNameBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/*
* @ORM\Entity(repositoryClass="VendorName\BundleNameBundle\Repository\repositoryClassRepository")
* @ORM\Table(name="table_name")
*/
class repositoryClass
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
sfidcolumn
/**
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
sfstringcolumn
/**
* @ORM\Column(type="string", length=100)
*/
sfdecimalcolumn
/**
* @ORM\Column(type="decimal", scale=${1:2})
*/
sfstextcolumn
/**
* @ORM\Column(type="text")
*/
sftwigextension
namespace VendorName\Bundle\BundleNameBundle\Twig\Extension;
class ExtensionNameExtension extends \Twig_Extension
{
/**
* Returns a list of filters to add to the existing list.
*
* @return array An array of filters
*/
public function getFilters()
{
return array();
}
/**
* Returns a list of tests to add to the existing list.
*
* @return array An array of tests
*/
public function getTests()
{
return array();
}
/**
* Returns a list of functions to add to the existing list.
*
* @return array An array of functions
*/
public function getFunctions()
{
return array();
}
}
sfroute
route_name:
pattern: /url
defaults: { _controller: AcmeTestBundle:Test:action }
If you miss something, feel free to fork this repository and send a PR with your awesome snippets for Symfony2 :)