Tuesday, February 12, 2013

Install symfony2 and doctrine using composer

1A) Download composer, which will download the composer.phar file which can be kept anywhere:

cd /path/to/composer/install/dir
curl -s https://getcomposer.org/installer | php

1B) Install symfony:

cd /path/to/composer/install/dir
php composer.phar create-project symfony/framework-standard-edition /path/to/webroot/Symfony 2.1.x-dev

2) Check the configuration

Go to http://localhost/Symfony/web/config.php

3) Configure the database

Edit the /path/to/webroot/Symfony/app/config/parameters.yml file

4A) If you already have the database table created, make sure that the primary key is named id.

4B) If you already have the database table created, you can skip to creating an entity class:

php app/console doctrine:generate:entity --entity "MySpecificBundle:Things" --fields="id:int(11) price:float"

5) Edit the src/.../Controller/DefaultController.php file to do something interesting with the database table.

For example:

$row = $this->getDoctrine()
  ->getRepository('MySpecificBundle:Things')
  ->find($name);

if (!$row)
  {
  throw $this->createNotFoundException('No row found for id: '.$name);
  }

$otherVariable = $row->getOtherVariable();

return array('name' => $otherVaraible);

6) Open your browser to http://localhost/Symfony/web/app_dev.php/hello/1 to view the row

7) To create a CRUD scaffold, perform the following command:

php app/console doctrine:generate:crud --entity="MySpecificBundle:Things"

Then open your browser to http://localhost/Symfony/web/app_dev.php/things


No comments: