Showing posts with label symfony. Show all posts
Showing posts with label symfony. Show all posts

Sunday, 25 October 2009

10 reasons to use symfony

I have been thinking about the added value of using a good development framework and here are my top 10 benefits of using symfony as a development framework vs traditional program development. I won't be talking here about the license, which is open source MIT (which is great) but specifically of the programming and features aspects.

Rapid Application Development
Write better code faster. I know it sounds too good to be true but this is definitely the most obvious benefit of using a good application development framework.

Promote good code design and OOP
Using the inbuilt MVC makes the code easier to maintain and design. The symfony documentation is full of guidelines to make code easy to use during the course of the various development steps. Also, it's built on PHP5 and is fully object-oriented. This again promotes good code design and reusability.

Concentrate on the essential
When building a web application, you often find yourself doing the same things over and over again. OK, the table names change from one module to the next, as does the data structure but the logic behind managing objects is mostly the same. So, why waste precious time on the standard "common" code, when you could be spending it concentrating on the much more rewarding essentials: specific business logic, security, usability, ... since those are the things which in effect rake in the money and differenciate your product from the next?

Encourage proper code documentation
Because the framework handles most of what's happening behind the scenes, it becomes much easier to document code as you go along. And, symfony integrates phpdoc by default.

Provide different environments
Ever found yourself thinking "Gosh, I wish I could just switch to development for a second just to see the detailed error" or "I wonder how this will work in production?". Well, symfony provides inbuilt mechanisms which allow you to simply switch from one to the other, without ever disrupting the actual production environment. This also promotes testing and thus application stableness and scalibility.

Increase security
symfony provides mechanisms, tips and suggestions for output escaping, preventing SQL injection, and CSRF attacks. You really need to read the documentation from cover to cover to take full advantage of all the options provided by the framework, but it's a worthwile read!

Abstract from database
Using a database abstraction layer and ORM makes the process of accessing data completely transparent. You no longer have to worry about actually accessing the database to create, retrieve, update and delete data. All the internals are hidden. You just access the objects via the ORM layer that sits above the database abstraction layer and that's it. Did someone say KISS? :)

Manage credentials
Managing credentials is dead-easy as symfony provides a simple plugin that does all the nitty gritty behind-the-scenes work for you!

Internationalize and localize
I guess this is probably one of the most important issues, certainly for European customers. Again, symfony creators have made this one of their key features and internationalization and localization is made easy by in-built ready-to-use mechanisms.

Join a living community
symfony is big, and getting bigger. It seems everyone today will agree one of the major advantages of open source is the community that builds around the project and provides support, ideas and new features to an already growing project. Neat.

Well, those are the top 10 I could think of. Of course, there are many other things like a.o. integrated Javascript frameworks (scriptaculous...), various helpers and simplified AJAX development.

What benefits do you associate with using a development framework (or symfony more specifically)?

Tuesday, 30 December 2008

symfony - upgrade1.2 and Propel 1.3 DSN

Yup, I have been fiddling around with symfony some more!
Since I installed the latest stable build of symfony (1.2.1), I decide to upgrade my projects using:

symfony project:upgrade1.2

The command processed fine but then all hell broke loose so to speak. Basically, the whole project went kaput. So...
I then ran the magic (that is in the non-PHP sense) command:

symfony plugin:publish-assets

Which fixed all my sfGuardPlugin issues!

My next problem was related to propel. I had my databases.yml file configured like so:

all:
propel:
class: sfPropelDatabase
param:
phptype: mysql
database: anxcity
dsn: 'mysql://root@localhost/anxcity'

I kept getting an Access denied error for user 'ODBC' which was strange since my DSN contained the user: root.

So... I tried the long form of the databases.yml declaration like so:

all:
propel:
class: sfPropelDatabase
param:
phptype: mysql
hostspec: localhost
database: anxcity
username: root
port: 3306
encoding: utf8
persistent: true

Then the system complained it wasn't receving the DSN string as planned.
So... I just added it:

dsn: mysql:dbname=anxcity;user=root;host=localhost;port=3306

That seems really trivial BUT ... you do need to use the exact string syntax for it to actually work (which is very different to the DSN string in my original configuration file).
And hey presto!

Thoughts?

Edit:
Ah yes, forgot to say I had to rebuild the model too, using:

symfony propel:build-model

Sunday, 28 December 2008

symfony - Ajax is not defined

I have been working on a small Ajax project using symfony - really trying to figure out how to get the nifty ajax functionalities working (using link_to_remote for instance).

I kept getting Ajax is not defined or Draggable is not defined errors and spent a couple of hours searching for the solution. Anyway, I finally came across this command:

symfony plugin:publish-assets


This got it all working for me - it simply copied the 'assets' (js scripts) to my /web folder. Simple :).

More code soon...

Thoughts in the meantime?

Thursday, 4 December 2008

Installing symfony - setting up the virtual host 2

Just a quick clarification on my previous post about setting up virtual hosts, which seems to be a little misleading.

You do also need to define your localhost as follows:

<VirtualHost *:80>
ServerName localhost
DocumentRoot "/path/to/www"
DirectoryIndex index.php
</VirtualHost>

(localhost should already be defined in your hosts configuration file).
This way you can still access all your other applications.

Thoughts?

Tuesday, 25 November 2008

Installing symfony - setting up the virtual host

Well, here is another thing that I have learned using symfony.

The basic installation tutorial instructs you to set up a virtual host for symfony:

<VirtualHost *:80>
ServerName myapp.example.com
DocumentRoot "/home/steve/myproject/web"
DirectoryIndex index.php
Alias /sf /$sf_symfony_data_dir/web/sf
<Directory "/$sf_symfony_data_dir/web/sf">
AllowOverride All
Allow from All
</Directory>
<Directory "/home/steve/myproject/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>


This was all new to me, so I set up "all" the paths correctly, and found that while it did allow me to use my symfony application properly and all the data_dir links where effectively aliased as planned, it also broke my other "localhost" links (e.g. I could no longer access http://localhost/other_app). Ouch.

Now I have figured out why: I hadn't changed the ServerName. So, the issue was solved by simply creating a new ServerName like so:

ServerName symfonyappname.localhost


To get this working the operating system must also be configured accordingly. To do this, simply add an entry to your hosts file, the location of which depends on which OS you are using.

Check out this link to find out where your hosts file is located.

Once the hosts file is properly configured (remember you may need to reboot), simply type:

http://symfonyappname.localhost

and magic happens :).

Thoughts?

Thursday, 13 November 2008

Netbeans support for Symfony

Now here's a nice and chewy piece of news posted by ppisl from netbeans.org:


The news is that the Symfony support will be part of NetBeans 7.0. We are going to start work on it very soon. I hope that it will be a part of continual build this year and community can comment the support and work with us to finish it in the best possible quality and usability.


This is straight from the Netbeans "issues" site: Issue 145913. You can vote to advocate Netbeans support for symfony from that same page. 468 votes so far...

According to the roadmap Netbeans 7.0 will probably be released around April 2009. It will be exciting to see how this pans out with the release of symfony 1.2 due in December of this year.

Anyone else looking forward to this?

Saturday, 25 October 2008

Plugin installation failed: No valid packages found

Well, I am still exploring symfony and its many interesting options. One of the features that really appeals to me is the ability to secure certain actions (e.g. "create", "save") for a given module (e.g. "user" module, "group" module) using user credentials (e.g. "admin", "guest"). The only catch is that this inbuilt mechanism doesn't provide login per se which means you can set credentials, but have to create the login process yourself. The most obvious way to avoid this is simply to install the sfGuardPlugin plugin for symfony.

I typed the installation command but came across the following:


cmd>> symfony plugin:install sfGuardPlugin

>> plugin installing plugin "sfGuardPlugin"
>> sfPearFrontendPlugin downloading sfGuardPlugin-3.0.0.tgz ...
>> sfPearFrontendPlugin Starting to download sfGuardPlugin-3.0.0.tgz (18,752 bytes)
>> sfPearFrontendPlugin .
>> sfPearFrontendPlugin .
>> sfPearFrontendPlugin .
>> sfPearFrontendPlugin ...done: 18,752 bytes
>> sfPearFrontendPlugin symfony-plugins/sfGuardPlugin requires package
>> sfPearFrontendPlugin "symfony/symfony" (version >= 1.2.0, version <= 1.3.0,
>> sfPearFrontendPlugin excluded versions: 1.3.0), installed version is 1.1.4

Plugin "sfGuardPlugin" installation failed: No valid packages found


The problem here was simply that the latest version of the package was being used. That particular version (3.0.0) is meant for symfony 1.2 which is still being developed. Since I am using the latest stable release of symfony (1.1.4), the trick is simply to specify which release to install. To work this out, simply check out the sfGuardPlugin changelog page to find the correct release version number (2.2.0).


cmd>> symfony plugin:install sfGuardPlugin --release=2.2.0


And hey presto, it worked! Excellent. More on symfony soon...

Thoughts in the meantime?

Tuesday, 14 October 2008

PHP Development Frameworks

As mentioned in a couple of previous posts (here and here), I have been looking into symfony as a PHP Framework solution and it's certainly one of the most comprehensive on the market. The following article at PHPit compares ten well-known PHP development frameworks including Zend, cakePHP and symfony.

Although the article is most probably outdated where facts are concerned (with comments dating back to 2006), most of the criteria on which the comparison is built are still very much up-to-date. They cover inbuilt support for: PHP5, Model-View-Controller (MVC), Object Relational Mapping (ORM), Caching, Validation and filtering, Ajax, Authentication, and more.

Still, I feel a development framework shouldn't simply boil down to supporting X or having inbuilt Y, and should in a sense embrace a wider philosophy as a whole.

Thoughts?

Sunday, 14 September 2008

symfony sandbox project, tutorial updated

In a previous post, I discussed a couple of issues relating to the symfony project sandbox tutorial.

It looks like the tutorial has since been updated however and I haven't really had the chance to check out the latest version but the parts that were highlighted in my post have definitely disappeared! Good news... :-)

To tell you the truth, I would like to move on to creating a web application from scratch (i.e. without the sandbox) so I will be starting at square one: The Definitive Guide to symfony and hope to be sharing some of this with you in coming weeks.

Thoughts in the meantime?

Thursday, 21 August 2008

Symfony sandbox project

I recently heard of the Symfony project. It's an appealing free open-source PHP5 development framework licensed under the MIT license and I decided to give it a go.

For starters I downloaded the sandbox version from:
http://www.symfony-project.org/installation/1_1

I had an easy-PHP installation already up and running on my Windows 2000 system. So simply dropped the sandbox project under my www folder and followed the instructions on the Symfony website using mySQL as database manager:
http://www.symfony-project.org/tutorial/1_1/my-first-project

It was all pretty straight-forward except for a few "catches" detailed below.

#1 - the project uses php.exe on the command line to generate configuration files, PHP classes, etc. You really need to make sure to copy the php.ini file to the folder where the php.exe is located in order for the configuration to be taken into account. You can check which modules are available (and in effect, whether your latest php.ini is getting loaded properly) by typing
php -m
on the command line.

#2 - I also activated the xsl extension. This gets rid of some error messages that occur during database configuration and creation. I am not sure whether this makes an actual difference on the end result but was trying to clear any errors as I ran into them.

#3 - When I tried to access http://localhost/sf_sandbox/web/frontend_dev.php/comment or http://localhost/sf_sandbox/web/frontend_dev.php/post as specified in the tutorial, the pages wouldn't launch properly, I was getting database error messages.
To avoid this, I had to manually configure the www\sf_sandbox\config\database.yml configuration file:

all:
propel:
class: sfPropelDatabase
param:
phptype: mysql
database: symfony_project
dsn: 'mysql://root@localhost/symfony_project'

I changed all three parameters: phptype, database (use the database name you chose), and dsn (note that root is using an empty password to connect here).
For changes to take effect, make sure to clear the cache using:
php symfony cache:clear

#4 - In the middle of the tutorial, it tells you to start using your new website.
However, when you try to add a comment you get the following error:
Class "Post" must implement a "__toString" method to be rendered in a "sfWidgetFormPropelSelect" widget
To fix this, open the
sf_sandbox\lib\model\Post.php
and add a __toString method as follows:


class Post extends BasePost
{
function __toString()
{
return $this->getTitle();
}
}


To be 100% accurate, also change the sf_sandbox\apps\frontend\modules\comment\templates\editSuccess.php file so that the Post id label becomes Post title or simply Post since the post title is what we're actually seeing now we have added the __toString method in the Post class.

#5 - I couldn't get the following to work:

Next, open the modules/comment/templates/editSuccess.php and replace the following lines:

<tr>
<th>Post:
<td><?php echo object_select_tag($comment, 'getPostId', array (
'related_class' => 'Post',
)) ?></td>
</tr>


The original code is slightly different in the sandbox version and the replacement code wouldn't work. One way to avoid this issue is to set the default post id in your comment actions class.
Simply open your sf_sandbox\apps\frontend\modules\comment\actions\actions.class.php and add the following in the "executeCreate()" method:

$post=PostPeer::retrieveByPk(
$this->getRequestParameter('post_id'));
if ($post)
{
$this->form->setDefault('post_id',
$this->getRequestParameter('post_id'));
}

This simply pre-selects the post title in the form when you access the 'new comment' page from a given post's page by setting the default value of the drop-down choice list.

#6 - in the same file (sf_sandbox\apps\frontend\modules\comment\actions\actions.class.php). Instead of using the code from the tutorial, simply replace the redirect line with:
$this->redirect('post/show?id='.
$request->getParameter('comment[post_id]'));

This will redirect to the correct post rather than to the comment page.

Well, that's it for now. I haven't finished the tutorial yet. I have only made it to just before the Form Validation chapter. So still lots of fun to be had - stay tuned!

Thoughts in the meantime?

[EDIT: it looks like the Symfony Sandbox Project tutorial has been updated so some - if not all - of the above information may no longer be applicable.]
Online Marketing
Add blog to our blog directory blog search directory Blog Directory Blogarama - The Blog Directory