Skip to content

Instantly share code, notes, and snippets.

@niepi
Created April 6, 2012 10:20
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niepi/2318674 to your computer and use it in GitHub Desktop.
Save niepi/2318674 to your computer and use it in GitHub Desktop.
Symfony2 Console Cheat Sheet

Symfony2 Console Cheat Sheet

idea and initial content from http://jamandcheese-on-phptoast.com/2011/12/18/symfony2-console-cheat-sheet/

CREATE A NEW BUNDLE

Structure

php app/console generate:bundle --namespace=[namespace]/[bundle name]Bundle --format=[bundle configuration format]

Example

php app/console generate:bundle --namespace=Moo/UserBundle --format=yml

namespace is your company name the prefix that will identify your bundles from other bundles that you may have in your application.

bundle name is what is it for? Examples of bundles: Blog bundle, User management bundle, Forum bundle, and so on. Bundle does not have to be accessbile from the web, you could create a bundle to manage internal functions such as integrating jQuery framework. You can create as many as you like of bundles under your company namespace

There are 3 types of configuration format that you can choose from YML, XML & PHP.

WEB RESOURCES. CSS, JAVASCRIPT & IMAGES

For operating system that does support symlinks

php app/console assets:install web --symlink

For operating system that does not support symlinks

php app/console assets:install web

As I said before bundles can be to manage internal functions (The jQuery bundle). These resources must be located under the directory

/src/[namespace]/[bundle name]Bundle/Resources/public/

This command is going to copy your files or create symlinks under

/web/bundles/[namespace][bundle name]

##CLEAR ENVIROMENT CACHE

Structure

php app/console cache:clear --env=[enviroment name]

Example

php app/console cache:clear --env=prod

–env is the name of the enviroment you want to remove its cache. Each subdirectory under

/app/cache/

is an enviroment.

INSTALL/UPGRADE BUNDLES AND SYMFONY2

php bin/vendors install

This commands installs or upgrade the bundles defined in the file

/deps

CREATE DATABASE WITH DOCTRINE2

php app/console doctrine:database:create

This command will create the application database based on the parameters defined in

app/config/parameters.ini

This command will not create tables, it just create an empty database if it does not exists else it will throw an error.

MAPPING DOCTRINE2 ENTITIES WITH THE DATABASE

Structure

php app/console doctrine:generate:entities [namespace]

Example

php app/console doctrine:generate:entities Moo

You can run this command after changes to the ORM metadata for the entity classes. It will create getter and setter methods. But it will not modify any of the existing methods.

CREATE TABLES IN THE DATABASE WITH DOCTRINE2

php app/console doctrine:schema:create

Based on the defined ORM metadata this command will create all of the tables.

If you don’t want to create the tables but return a dump of the SQL queries, then pass the following option

--dump-sql

to the right side of the command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment