Updated May 12th, 2013
Symfony

Updated Thoughts on Symfony

The biggest problem I see with Symfony is that it requires you to master a wide array of incredibly cryptic syntax, all of which will become completely useless if you want to use your code in a place that is not Symfony. In other words, there is little portability between this framework and any other, which really minimizes it's usefulness.

The one thing I can definitively say, is that there is no perfect framework. You will jump around between a few great ones. It's best to choose ones that don't require mastery of a

My Thoughts on Symfony

Just came from Codeigniter and wanted something that helps me out with database interaction.

As lovely and minimalist as Codeigniter is, this bites itself in the ass if you're dealing with a project that has tables. If a system forces you to write your own crud interface for every table you create, you're just not going to do it. Why? Because the extra effort isn't going to be worth it, there are more productive things to do than build tools to support the backend of the application.

My view on this is evolving. At least if you build your own interface, you can very easily reuse the code without having to reformat it for a new framework. I'm getting sick of the trail of dead I've left behind as I switch between platforms. (7/24/2012)

This means spending time in SQL whenever something goes wrong. So you've painted yourself into a corner. It takes too much time to write code that you may not use, but if something goes wrong you're going to spend a lot more time and mental energy fixing it.

Enter Symfony, which provides ORM, integration with a sweet templating system (twig), unit testing, and a console which allows you to create databases and crud interfaces. Nice.

However, so far there a few snags. There is a definite learning curve with this, errors are not particularly transparent, and console commands are not intuitive. Unit testing seems to be a lot of effort, and the file system is organized by someone who has different priority than I. (So my views are in src/MyProject/Resources/Views but my layouts are in app/resources/views... what?)

I really was surprised how a templating language like twig makes me FEEL warm and fuzzy about my templates. It is clean and sexy. I should continue this in a different note.

Update: Twig is just another technology to learn that increases the difficulty of porting over code from one thing to another.

Cons

The documentation is awful. Request->get says "Avoid using this method in controllers" but there is no alternative given. Having to explicitly "use" all these bundles in controllers is awful. I doubt anyone knows off the top of their head the proper ones to include.

Note: I am exploring the documentation more thoroughly, there is a bit of light at the end of the tunnel. Perhaps there's just a learning curve for the documentation.

The error messages tell you nothing. You are completely on your own.

Fixtures and unit testing are not simple enough. The barrier is use is too high.

Doctrine Entity Manager is a little.. odd

The folder structure is crazy.

Console commands are really hard to type

Pros

ORM makes accessing complex database relationships sooo easy. Twig makes displaying it so nice and clean. The security file makes putting easy passwords on pages a synch!

ORM - Instead of having to write a usort function to sort my results, I can simply use @ORM\OrderBy, and it's done at a database level without having to write sql code

Assetic - have not fully untapped this, but I like the idea of being able to use coffeescript and less.

Deployment

cache:clear --env=prod

ORM

@ORM\OrderBy({"card_order" = "ASC"})

useful console commands

g:bundle

g:doctrine:entities

doctrine:schema:update --force

g:doctrine:entity --entity="FunTestBundle:Card" --fields="name:string(255) price:float"

g:doctrine:crud --entity=FunBundle:Card --with-write

g:doctrine:form FunBundle:Card

router:debug

$response = $this->redirect($this->generateUrl('_scoreboard'));

php bin/vendors install // run this to use deps to update vendors

database

http://symfony.com/doc/current/book/doctrine.html http://symfony.com/doc/current/book/doctrine.html#book-doctrine-field-types http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/association-mapping.html

form builder ManyToMany

->add('challenges', 'entity', array('class' => 'FunBundle:Challenge', 'multiple' => true, 'property' => 'name'))

fixtures

[doctrine-fixtures] git=http://github.com/doctrine/data-fixtures.git

[DoctrineFixturesBundle] git=http://github.com/symfony/DoctrineFixturesBundle.git target=/bundles/Symfony/Bundle/DoctrineFixturesBundle

  1. php bin/vendors install
  2. add to autoload
  3. add to AppKernel

field-types

string (used for shorter strings) text (used for larger strings) integer smallint bigint decimal float date time datetime boolean object (serialized and stored in a CLOB field) array (serialized and stored in a CLOB field)

clear cache: console cache:clear --env=prod --no-debug

Install Symfony Locally in 9 Steps:

1. Ran php app/check.php - got error:
    php.ini used by PHP WARNING not using a php.ini file
    Checking that the "date.timezone" setting is set FAILED
2. php -i | grep 'Configuration File' - this shows where php.ini should be
3. create  /etc/php.ini
4. add this line: 
    date.timezone = "America/New_York"
5. Ran php app/check.php - Success! - Ignored Warnings:
    - "Checking that the intl extension is available: FAILED"
    - "Checking that a PHP accelerator is installed: FAILED"
    - "Checking that php.ini has short_open_tag set to off: FAILED"
    - "Checking that php.ini has magic_quotes_gpc set to off: FAILED"
6.  point Mamp to dir_with_symfony/web
7.  Goto localhost:8888/config.php
8.  What?? Major errors:
    - "You are running PHP version "5.2.17", but Symfony needs at least PHP "5.3.2" to run. Before using Symfony, install PHP "5.3.2" or newer. (Hmm. )"
    - "Change the permissions of the "app/cache/" directory so that the web server can write into it."
    - "Change the permissions of the "app/logs/" directory so that the web server can write into it."
    - "Set the "date.timezone" setting in php.ini* (like Europe/Paris)."
9. Set Mamp to  php 5.3.6 in preferences.
10. COMPLETE!

Create Database (for MAMP):

Goto /etc/php.ini, add this: pdomysql.defaultsocket="/Applications/MAMP/tmp/mysql/mysql.sock"

installing PHPUnit:

1. Download Pear: curl http://pear.php.net/go-pear.phar -O
2. Run: php go-pear.phar
3. Install: hit enter a bunch of times
4. Prep for PHPUnit: pear config-set auto_discover 1
5. Install - pear install pear.phpunit.de/PHPUnit:
  got this error: |
  Warning: require_once(File/Iterator/Autoload.php): failed to 
  open stream: No such file or directory in
  /Users/____/pear/share/pear/PHPUnit/Autoload.php on line 45
  Fatal error: require_once(): Failed opening required
  'File/Iterator/Autoload.php' (include_path='.:') in 
  /Users/____/pear/share/pear/PHPUnit/Autoload.php on line 45
6. Fix install if broken: pear install --force --alldeps phpunit/phpunit

7. Hmm still not working.. after reinstalling pear found this: WARNING: Cannot write to /private/etc/php.ini, but php.ini was successfully created at </Users/bokeh/pear/php.ini-gopear>. Please replace the file </private/etc/php.ini> with </Users/bokeh/pear/php.ini-gopear> or modify your php.ini by adding: include_path=".:/Users/bokeh/pear/share/pear" 8. Works!!!!

Using Images in Symfony:|

{% image '@SomeBundle/Resources/public/images/someimage.png'} {{ asset_url }} {% endimage %}

Errors:

php error: |
    [20-Feb-2012 17:37:07] PHP Parse error:  syntax error, unexpected T\_STRING, expecting T\_CONSTANT\_ENCAPSED\_STRING or '(' in /Users/______/me/sites/fun/web/app.php on line 7
solution: Change mamp to use the latest php, (in my case 5.3.6)

Allowed memory size of 33554432 bytes exhausted: "console cache:clear --env:prod"

Twig

put base.html.twig in app/resources/views {% extend '::base.html.twig' %} parent() // brings in base block instead of overwriting it

Components

  • ClassLoader
  • Console
  • CssSelector
  • Dependency Injection
  • DomCrawler
  • Finder
  • HttpFoundation
  • Locale
  • Process
  • Routing
  • YAML

Folders

Src - all my bundles Vendor - everything else Vendor/Bundle/lib ?

Learn

Service Container Modular Services Components

Symfony Instalation (local): 1. Ran php app/check.php - got error: php.ini used by PHP WARNING not using a php.ini file Checking that the "date.timezone" setting is set FAILED 2. php -i | grep 'Configuration File' - this shows where php.ini should be 3. create /etc/php.ini 4. add this line: date.timezone = "America/NewYork" 5. Ran php app/check.php - success! 6. opened localhost:8888/web/config.php 7. warnings: install intl extension shortopentag to off (I'm disregarding this) set magicquotes_gpc to off (not sure if i really need to do this)