Symfony or Yii…What to choose?
Posted September 9, 2013on:
When looking for a suitable web framework you could definitely come across – Symfony and Yii – top PHP frameworks. But what to choose? Most interviewed developers prefer Symfony than Yii. Let’s see why.
Code maintenance and management. I believe there is no problem to create a code from the very beginning. Still when it is a long term project there could arise some issues – for instance, after several months of the development on Yii there could arise some problems with small workarounds, hooks…it would definitely work but supporting would kill you. Protection from corruption is quite important for every company but who would like to care about hooks and workarounds everyday if these issues could be avoided?
Style of the code. Yii team has their own code style, it’s great. Still it can be a problem in case you have a project with different code guidelines than Yii team use. Sure, you can contribute some extensions in Yii community and save the extensions similar to native Yii code. But in the end you would have to switch between different code guidelines all the time – not great. Namespaces. Namespaces helps to shortcut class names, helps with classes autoloading etc. Yii doesn’t not use them. I believe you would feel more comfortable with namespaces.
Test driven development (TDD) issue. As for code testing, tests should be written easily. In case Yii, its global service locator (Yii::app()) destroys attempts to write tests. Starting with one test, after some time you would understand that you would need to mock this service and another one, and both of them depends on 3rd service…in the end many services interact with each other in Yii L As a result we get tight coupling, which is tricky for performing decoupling application.
Thus, in spite of Yii has CWebTestCase, fixtures, base integration with phpunit etc it is more useful to test services/models without mocking other services and framework classes.
ActiveRecord. Having ActiveRecords as framework core is great, it’s really useful for beginner. Still Yii active record is too simplified and tightly coupled. Another more serious issue – there is no separation between entity and entity manager. Using Yii we have to use static methods for querying models and non-static methods for model logic. ActiveRecord and ActiveFinder are provided by a single instance in Yii and there could be a trouble when queries mixed with entity getter/setter.
Ah, regarding to static methods for querying, they can’t have state except for static one. And if you want to mix few conditions you have to merge criterias. What is Symfony in this case about? It has Doctrine 2 – quite serious ORM with unit of work and other cool things. Or as an option you can try Propel ORM. There is the things you would really like: real getter/setter, db schemas and migrations generation, behaviors that actually a generator addons, reach set of generator properties and integration in some Symfony components like forms and validator. It has some issues as well, still it works better and you can get clear separation between entities and queries.
Extensions. As for extension in Yii, firstly you should find and download it on the Yii site, manually copy it to the project directory, attach it in config. And then to monitor the site for updates. Such procedure is not comfortable for 21th century. Composer could be a great choice in this case. You can easily define project dependency and run update. It download extension/lib/component/bundle or whatever you want, setup autoloading and you can use it. Also composer cares about all component dependencies and downloads them. All components can be updated to most up-to-date version with one command. Also you can specify which version to use: to download test or dev versions , it’s easy!
There is another cool thing – contributing. It’s easy to publish your package and make it globally available, easier to define versions, easier to fork extensions, easier to send pull requests etc.
Now some short facts about Symphony:
- Symfony is not a framework but a project. Depending on your needs, you can choose to use some of the Symfony Components, the Silex micro-framework, or the full-stack framework.
- Symfony is used by many large companies (like the BBC or CBS), by many large websites (like TED, wetter.com, Lockers) and some Open-Source projects are also powered by Symfony (CMSes likeDrupal or eZpublish, libraries like PHPUnit or Doctrine, products like phpBB orshopware).
- Symfony enjoys a huge community of users and contributors; during the last year alone, 550+ people contributed to the Symfony core and the community created over 1,600 bundles for the full-stack framework. Symfony also has several annual dedicated conferences around the world and a large number of user groups.
- Symfony has been created in 2005 and here to stay. Besides SensioLabs, many other companies rely on Symfony for their clients and they contribute, invest money, and sponsor the future of the project.
- Symfony embraces the “don’t reinvent the wheel” philosophy, and provides tight integration with many other Open-Source projects.
- Symfony tries to bring innovation to PHP: it was one of the first major frameworks to embrace PHP 5.3, to introduce the usage of a Dependency Injection container, and to use a templating engine for its templates by default,Twig, which is now also adopted by major CMSes like Drupal and eZpublish. Symfony also has some unique features like its gorgeous debug toolbar and its great built-in profiler.
Conclusion. In case you would like to create a small blog – Yii would be a great choice. If you are going to develop a serious application, if you know why you need a Dependency Injection, and need to cover most of the code tests, need a super plug-in architecture, work with migrations and a fixture – only Symfony.
Thank you for your attention and look forward to your thoughts.