Symfony2 and MVC

Really like what Fabien expressed here:

Is Symfony2 an MVC framework?

If you look around, every single framework seems to implement the MVC pattern.

I really don’t care whether Symfony2 is MVC or not. Probably because the MVC word is so overloaded and because nobody implements exactly the same MVC pattern anyway. The separation of concerns is all I care about. And if you like to call Symfony2 an MVC framework, then you should know that Symfony2 is really about providing the tools for the Controller part, the View part, but not the Model part. It’s up to you to create your model by hand or use any other tool, like an ORM.

I don’t like MVC because that’s not how the web works. Symfony2 is an HTTP framework; it is a Request/Response framework.

You have to be very discipline when you use Symfony2. Unlike other frameworks there are often many way of achieving the same result. I find myself thinking which is better often, changing where I place certain code and still lack the satisfaction and confidence that I did right. I am unsure where this and that should go although I will just say that given my experience with PHP I can pretty much make anything work. But. They just aren’t very sightly, if you know what I mean.

Symfony 2 is hard

Symfony2 is hard. But not simply because it is doing things so differently, rather, it depends on so many packages. While there are certainly a lot of resources online, many can be considered outdated.

This recalls a discussion I had with U-Zyn of gladlyCode on the trends on PHP frameworks. We concluded that Symfony has a brighter future because on the past few years Symfony has became one of the most talked about frameworks in Google Trends. That observation, however, did not consider the scenario where more people posted online as they needed help. Additionally search for Symfony also includes Symfony Legacy (Symfony 1) which turns out to be vastly different from Symfony 2. It is hard to distinguish articles of the two, half the time I’ll be read through then to realized it’s for Symfony 1

Symfony 2 supports both Doctrine 2 and Propel ORMs. There are times I read through articles for Propel rather than Doctrine2 that I am using. Yesterday I spent my day figuring out Symfony and all I achieved is installing bundles. Bundles are not as well documented and many times that are wrappers of another PHP project.

At the end of the day I find myself referring to so much websites that I maxed out my tabs and no longer see the favicon on the tab any more.

Symfony2 reminds me of TurboGears of Python, if anyone is even still using it. It’s not a bad thing, especially in the whole of PHP where writing yet another ORM isn’t really needed. My minor complaint is Symfony requires the developer to do more configuration than other frameworks — say Yii Framework — and the ORM of choice, Doctrine 2, requires too much definitions to be included in an Entity (similar to Model of MVC frameworks). Overall Symfony 2 is a big framework to work with, I am probably discovering something new at every juncture. It’s worth a try but you’ll need a day at least to explore their features.

How to use Symfony with existing database

I recently had to start a Symfony2 project using an existing database. Here is a rough guide on how it is done.

Firstly you have to update your app/config/parameter.ini to your existing database:

[code lang=”bash”][parameters]
database_driver=”pdo_mysql”
database_host=”127.0.0.1″
database_port=””
database_name=”gladlycode”
database_user=”root”
database_password=”root”
mailer_transport=”smtp”
mailer_host=”localhost”
mailer_user=””
mailer_password=””
locale=”en”
secret=”0bdc03a00514e9c1595219d165115d532″
[/code]

My bundle is named GladlyCodeBundle, you will have to rename this. Based on this I do a map of existing database tables into XML format, note that the em dash is 2 dashes due to conversion by WordPress:

[code lang=”bash”]php app/console doctrine:mapping:convert xml ./src/Gladly/CodeBundle/Resources/config/doctrine/metadata/orm –from-database –force[/code]

You need to change the ‘Gladly/CodeBundle’ part to fit your project as the next step will look to import from the default location.

If you get any errors of this sort:

[code lang=”bash”]PHP Fatal error: Call to a member function getColumns() on a non-object in /Users/kahwee/projects/gladlycode/vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php on line 133
PHP Stack trace:
PHP 1. {main}() /Users/kahwee/projects/gladlycode/app/console:0
PHP 2. SymfonyComponentConsoleApplication->run() /Users/kahwee/projects/gladlycode/app/console:22
…[/code]

It could be due to one of your tables not having a primary key. Just assign it the appropriate primary to continue with the import process.

Then I import them with annotations:

[code lang=”bash”]php app/console doctrine:mapping:import GladlyCodeBundle annotation[/code]

Finally I regenerate them into entities:

[code lang=”bash”]php app/console doctrine:generate:entities GladlyCodeBundle[/code]

And that’s it. Everything is imported.

Composer, a package manager for PHP

Composer is probably a bad name for a package manager in the sense where it is hard to research online by searching on the keyword ‘composer’ without receiving Beethoven as part of results. The composer I am referring to is this. Composer is a package manager tracking local dependencies of your projects and libraries.

Composer lets you specify your dependencies in a composer.json file looks like this:

[code lang=”javascript”]
{
“require”: {
“doctrine/common”: “2.1.*”,
“monolog/monolog”: “>=1.0,<1.2-dev”,
“swiftmailer/swiftmailer”: “>=4.1.2,<4.2-dev”,
“twig/twig”: “>=1.1,<2.0-dev”
}
}
[/code]

This file will install the components into the a vendor folder on the directory where you execute the following:

[code lang=”bash”]php composer.phar install[/code]

Just got Fitbit

I just got Fitbit.

Got it fulfilled through Amazon from US. Fitbit is manufactured in Singapore but I cannot get it here.

Will update more on how it works after a week of usage. It’s pretty cool so far.

Above is a screenshot of what I did today. It’s not very accurate on the steps part though. I don’t think I ran that much steps today. It’s an extremely simple to use device and is compatible with Windows and the Mac.

Stop receiving paper bills

Get sent bills? If you are discipline enough to pay your bills online every month, consider getting electronic bills instead. And why?

  1. You save on paper and do your part on conservation, making Earth a better place
  2. You no longer to open envelopes which takes up time and your bills often comes with additional advertisements that is thicker than the  bill itself
  3. You never have to feel compelled to file them because electronic bills are archived online already

So just get rid of paper bills altogether. It makes you more free since you have lesser to do. You can dedicate your time on the littles things you plan to do but didn’t, such as in my case getting a wardrobe. Doing little things an hour a day will get you closer to what you envision.

The bonus is having to deal with lesser physical items. If you still get paper bills, consider throwing away the less important ones after you paid the bill. As much as possible, file as little as possible. This reduces unnecessary worries.

The new wardrobe

The past 5 years I have been greeted with the thought of having to get a bigger wardrobe every time I look at my wardrobe. I have been stressing over and over that I needed a need wardrobe to many.

It just occurred to me one day, a fine 16 May 2012, that I should execute this — get a wardrobe and probably rid the bed I don’t like to look at. I wasn’t acting transgressive enough when it comes to ridding a bed that is working well.

It came to me that every morning I keep telling myself the same thing again: get a new wardrobe; get a new bed. All these moments I spent having that thought would, by now, gather to be several hours. It bothers me so much apparently that I encounter much displeasure just opening the wardrobe door. I dislike the way it creeks, I dislike the wood pattern, I dislike the way the cupboard doors don’t align right when it was shut. I started picking more and more things and I realized I have no way out but to get a new one and rid the old.

So on 16 May 2012, I went to Ikea.

I am liberated.

My trip to Taiwan

I doubt I will have time to put up what happened in Taiwan as much as I would like to. There’s just too much commitment here.

I do miss writing personal experiences, though. I might be getting more boring as I grow older.

The Taiwan trip has been great, filled with experiences I can never get from Singapore. I traveled with my brother and my cousin this time. Our differences made scheduling a itinerary a challenge; nevertheless we did achieve our personal vacation objectives generally. We went to Taipei and stayed in the Ximending area (Ximen station).

I will post pictures when I am free.

My absence in Singapore from 17 May to 22 May has caused trouble, still the thought of returning and facing these issues dampens my mood.