Tuesday, 13 March 2012

Random Symfony2 reminders

This post is basically a crib sheet of Symfony 2 reminders for myself, but you're welcomed to use it if it helps. It's a short list right now, but I'll be periodically adding to it.

List available app/console commands

$ php app/console list

Useful DQL examples

Install web assets

$ php app/console assets:install web

The optional parameter --symlink will use symbolic links instead.

Force schema update

$ php app/console doctrine:schema:update --force

Note: consider using Doctrine Migrations instead

Create tables

$ php app/console doctrine:schema:create

Note: don't run this in a production setting

Create database

$ php app/console doctrine:database:create

Generate setters and getters

$ php app/console doctrine:generate:entities Package

Generates setters and getters for all entities in Package.

ORM annotation Column() options

  • type (optional, default 'string')
  • name (optional, default to field name)
  • length (optional, default 255)
  • unique (optional, default FALSE)
  • nullable (optional, default FALSE)
  • precision (optional, default 0) The precision for a decimal column.
  • scale (optional, default 0) The scale for a decimal column.

Install doctrine fixtures in Symfony 2.1

Step 1 (only if necessary): install Composer

$ curl -s http://getcomposer.org/installer | php

Step 2: Update composer.json

    "require": {
        "doctrine/doctrine-fixtures-bundle": "dev-master"

Step 3 (optional): allow only stable updates in composer.json

Look for the key "minimum-stability", and change its value from "dev" to "stable", e.g.

"minimum-stability": "stable",

Step 4: update vendors library

$ php composer.phar update
Step 5: register in AppKernal.php
// ...
public function registerBundles()
    $bundles = array(
        // ...
        new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
        // ...
    // ...

Generate a new bundle

$ php app/console generate:bundle --namespace=Package/YourBundle --format=yml

Generates a new bundle named PackageYourBundle in the namespace named Package/YourBundle.

No comments:

Post a Comment