Choose a right PHP framework


PHP frameworks give us common structures to normalise web apps, support productivity, revoke repeated coding and emanate some-more fast sites. Kai Chan helps we collect one

This essay initial seemed in emanate 227 of .net repository – a world’s best-selling repository for web designers and developers.

Frameworks yield a substructure where developers’ formula can be orderly arranged. Documentation, common problems, solutions, tips and recommendation can be common online in an open source fashion. In a days before web frameworks, it was common to see sites combined in a exclusive fashion. Different coders would occupy their possess arsenal of techniques and methodologies in arranging their formula and conceptualizing their architecture. This would emanate a series of issues: miss of documentation, formidable exclusive frameworks – or a common box of ‘what happens when a programmer leaves?’.

Choose a right PHP framework

Frameworks yield a good substructure for third-party plug-ins. For example, we can supplement personalisation algorithms and offer something identical to ebay

Developers mostly attempted to solve a problem of organising formula by following a routine of ‘separation of concerns’, fundamentally violation bigger problems down into smaller ones and imprinting out graphic operative bounds between sections of code.

Templating engines supposing another useful apparatus to assistance web app development. Smarty Template Engine is a longstanding, renouned library enabling easy subdivision of a dual areas of formula web devs mostly understanding with: a era of calm (aka a business logic) and how it’s displayed (the arrangement markup or view).

Frameworks unequivocally came into use in 2004, when they offering themselves as a extensive resolution to building clever websites. Most of a renouned PHP frameworks are predominately formed around a settlement methodology called model-view-controller or MVC for short. It’s almost no fluke that a apparent Ruby on Rails MVC horizon launched around mid-2004; this will positively have been an impulse for many other PHP frameworks.

One of a initial PHP MVC frameworks on a stage was a Mojavi Project, sadly no longer active. Nowadays, however, there are many frameworks fighting for a attention. In this essay we’ll cover a 4 critical frameworks that are now mostly used in a industry: CakePHP, CodeIgniter, Symphony and Zend.

What accurately is a framework?

So what is a PHP framework? Essentially, it’s a set of PHP classes and functions that developers go to when building a site. The MVC indication can be noticed as an prolongation to templating engines. Here is a discerning explanation:

  • Model: The indication contains a server business proof code. This customarily involves a reading and essay to a database in further to some pre- or post-processing. For example: ‘A user enters a comment, yet before we insert it into a database, we need to do a spam check with; if it passes we can do a insert.’
  • View: This is where we benefaction a outlay to a user in a sold format, many mostly HTML markup, nonetheless it can be a JSON or XML format. For example: ‘We need to arrangement all a comments for a forum topic, a indication fetches all a comments and are afterwards review and formatted by a view.’
  • Controller: The controller is radically a manager. It initial intercepts a URL, afterwards calls a scold models and views before presenting it to a browser, mobile device or an API caller. For example: ‘In displaying all a comments for a topic, a controller creates a tangible call to a indication and afterwards passes a indication information to a view, that afterwards generates a HTML output. This generated perspective is afterwards shown to a pursuit browser by a controller.’
PHP Frameworks

There are many frameworks available. Sites such as PHP Frameworks make it easy to review and contrariety so we can collect a right one for your needs

A horizon gives we a good tangible coding template where we need to place certain forms of code. The following ultra elementary PHP formula will give a coder’s perspective on how MVC works in general. It displays a stream continue where we are!

  1. <?php
  2. // The continue “controller”
  3. function controller_weather() {
  4. $type = model_weather();
  5. echo view_weather( $type );
  6. }
  7. // Get a stream data/weather, a “model”
  8. function model_weather()
  9. // get a data
  10. $status = ’Look out a window!’;
  11. return $status;
  12. }
  13. // Generate HTML presentation, a “view”
  14. function view_weather( $type ) {
  15. // settlement and blueprint should be here
  16. return &lsquo;<b>Weather where we are:</b>
  17. ‘.$type;
  18. }
  19. // prevent URL and call a applicable controller
  20. if ( strstr( $_SERVER[ 'REQUEST_URI' ], ‘/weather/’
  21. ) ) {
  22. controller_weather();
  23. }
  24. ?>

A common mistake is blending formula between controller and model. Business formula should ideally all be in one place: in a model, or indeed a thirdparty library. A good doubt to ask yourself is, ‘would other controllers use this logic; is it a ubiquitous square of code?’ If yes, afterwards it should go in that one place, a indication being a many common one.

There is still some difficulty as to where business proof should be placed, in controllers or models. Just Google ‘fat models spare controllers’. Much of a problem stems from a fact that ‘business logic’ is a hairy term.

In an MVC framework, controllers conduct and flue information between a browser, models, and views

Another good proceed to have a purify subdivision between business proof and perspective is to rise an API to promote formation to other systems. This some-more or reduction army a web group to build a clever complement given a same square of business proof contingency be variable to opposite scenarios. In addition, care of this needs to be in place right from a start of a project.

The perspective is many easier to demarcate: we can usually have programming arrangement syntax in a view. Controllers and models should never enclose any arrangement syntax, for instance br/. You will be in vast difficulty if we do!

How can it help?

Using a horizon competence not be a answer to any project. You need to demeanour during your sourroundings and decider how good a horizon can fit in. Here are some pros and cons in regulating frameworks:


  • Frameworks can be used as a fast focus growth process ( rapid_application_development), enabling discerning prototypes to be developed.
  • As any plan is formed on a identical structure, it allows for a faster growth cycle.
  • Developers can simply burst from plan to plan yet worrying too many about a structure of a code.
  • Plays good with Agile program development.
  • The underlying formula will change reduction often, ensuing in a some-more fast site.


  • Some frameworks have a high training curve.
  • It can be formidable to find developers with believe of a sold framework.
  • Not all frameworks are bug free
  • Hackers can feat weaknesses in frameworks.
  • Different frameworks’ interpretations and ancillary libraries of a MVC element can vary.

PHP frameworks and frameworks in ubiquitous are customarily within a domain of developers. However, other parties within a web plan have opposite needs when it comes to frameworks:

  • Managers/owners: The 3 opposite domains of model-view-controller within a horizon give managers a proceed to order tasks into docile chunks. For example, a developer operative within a Products indication need not worry about how it’s used externally. The outmost arrangement is dealt with by a View. A horizon in hint enables easier together development. Agile growth is a plan government process that goes good with frameworks. With many collection accessible in almost all frameworks and a purify structure managers can understand, fast growth and turnarounds are a norm.
  • Designers: The visible illustration will always be a formidable charge to combine into code. Using an MVC horizon helps yet a charge is still vapid and difficult. Developers need to apart a settlement into a sold components and splice it into a suitable views. This is where CSS frameworks can infrequently help.

Convention over configuration

For frameworks to understanding with a crowd of scenarios, settlement sourroundings is an critical area. Most frameworks opt for a ‘convention over configuration’ settlement solution. For example, if a PHP category for a indication is called model_students, a database list should be named students and a PHP category for a analogous perspective should be called view_students. This lowers a complexity of settlement settings, as seen in a before PHP continue example.

Configuration files offer some-more coherence and control; a obstacle is they can supplement complexity in comparison to gathering over configuration.

The following is a settlement dash of formula from Symfony’s routing file:

  1. # app/config/routing.yml
  2. hello:
  3. pattern: /hello/{name}
  4. defaults: { _controller:
  5. AcmeHelloBundle:Hello:index }

The analogous formula is simply a ‘hello world’ script: if a URL is, for example,, afterwards a outlay is ‘Hello Bob’. The dash of syntax above matches a URL with a suitable square of controller code.

View separation

One of a arch problems that a use of MVC frameworks solves is separating business proof from a outlay of data. Mixing some formula into arrangement proof is unavoidable when regulating a framework. However, we wish to keep any arrangement markup out of a controller – and, some-more importantly, a model. So in a elementary continue example, if we confirm to supplement a confidant HTML tab b, it would be deliberate bad use since it will almost means problems if a arrangement is in JSON or XML.

  1. function model_weather() {
  2. // This is bad!
  3. // No arrangement markup authorised in model!!
  4. // Fix or else!
  5. $status = ’<b>Look out a window!</
  6. b>’;
  7. return $status;
  8. }

Database support

Web apps many mostly use a database to store permanent user data. All 4 critical frameworks have good support for MySQL and other common database drivers such as Oracle and MS Server. There is a associated program member called object-relational mapping (ORM), that some frameworks use. Symfony in sold creates complicated use of Doctrine, a third celebration ORM that can also be used in other frameworks. ORM aims to facilitate a database formula within a web project.

The Bakery

Offering tutorials, segments of formula and news, The Bakery provides one of a clever points of a CakePHP horizon experience


All a critical frameworks we’re deliberating have village support; CodeIgniter is generally active. Pay courtesy to a series of tutorials for any horizon combined by bloggers: a many indispensable apparatus in assisting developers know a framework. Noteworthy fact: Symfony done a critical chronicle ascent in 2011. Knowledge relating to a new chronicle 2 competence not be relevant; however, chronicle 2 is a critical change to a proven framework.


Documentation is critical as a indicate of central reference. There shouldn’t be a need to puncture by a source formula to see how things should work, yet it is a common occurrence. Documentation should have good examples to go with any feature. What’s more, a good horizon should also have a accumulation of books, forums and video tutorials.

Additional horizon features

  • Helper functions: These are mostly plain PHP functions that perform one charge only, email validation for example.
  • Caching: This is removing some-more critical as some-more calm is accessed in a wider accumulation of ways. All frameworks have varying degrees of caching mechanisms. Many web owners also opt for thirdparty collection such as Squid.
  • Unit testing: This enables programmed contrast of formula within your app. For critical projects we should try to supplement some section testing. All a frameworks reviewed possibly have their possess section contrast methods or use PHPUnit, that is flattering many a de facto PHP contrast suite.
  • Form generation: Here frameworks can unequivocally shine. Forms are so prevalent in web apps that many frameworks have era or validation facilities to assist developers in adding web forms.
  • Session: The event facilities within PHP already work utterly well. Most frameworks supplement facilities on tip of a existent PHP session. Zend, in particular, has good event control functions.
  • Templating: This refers to how formula is organized within a view. It tries to answer a question, ‘what’s a best proceed to organize formula within a view?’. Smarty Template was an early resolution before to MVC frameworks. In a context of this article, Symfony is a usually horizon regulating a templating software, called Twig. It’s really identical to Smarty Template and was grown by a same association as Symfony.
  • Extending/third-party module: Third-party plug-ins and themes have been a pushing force behind growth platforms such as WordPress and Drupal. Some MVC frameworks aim to do a same; flattering many all of them have easy third-party extensions or plug-ins, with a difference of CakePHP. Frameworks need to do some-more in this area.
  • ACL: Access control and log-in government is a common underline of many web apps. All a frameworks yield varying levels of facilities relating to what is mostly called Access Control Lists (ACL). CodeIgniter is a usually horizon where we need to hunt a web for third-party ACL plug-ins.

Main contenders

There are good over 20 opposite open source PHP frameworks; this mostly causes a critical box of mind freeze. However, in new years, a 4 critical frameworks CakePHP, CodeIgniter, Symphony and Zend have gradually come to dominate.

This is down to prolonged life, village support and support help. Features aren’t used since they mostly do identical things, and if a horizon lacks a feature, it’s expected a third-party plug-in will be available. How one produce is improved than another is mostly a matter of personal philosophy, past believe or stream operative environment.

Out of a 4 frameworks, CodeIgniter and CakePHP really many go together, with CodeIgniter a easiest to collect up. This is followed by Zend and Symfony, since they’re really similiar. Symfony has a steepest training bend in comparison to Zend, overdue to a larger physique of believe that needs to be picked up.

1. CakePHP

Pros Active community; Cake Bakery (bakery.
Cons Cake has really specific ways of doing things

This horizon takes impulse from Ruby on Rails and really many belongs to a KISS (keep it elementary stupid) camp. Its horizon structure is easy to understand. There are folders for controllers, models and views. Most web apps will have many of a formula contained within these 3 folder types.

The prominence of CakePHP is a Cake Bakery where third-party developers can supplement their possess formula and share it with a community. CakePHP is a good center ground, not as elementary as CodeIgniter, yet not utterly as formidable as Zend or Symfony.

CakePHP doesn’t have add-ons such as ORM or a template engine. Out of a 4 frameworks, this is a usually one that doesn’t have corporate subsidy – yet that could be seen as a and point.

2. CodeIgniter

Pros Speed; really lightweight; vast active community, good documentation
Cons Can concede too many leisure in coding

Created by EllisLab in Oregon and expelled shortly after CakePHP, in 2006, this is good in projects where a best of multiply proceed is favoured. You can supplement other third-party program yet feeling weighted down, and like CakePHP and Zend, it has a transparent MVC folder structure that we can follow. CodeIgniter also gives developers some-more headroom to solve problems according to their thinking, distinct Zend or Symfony, in that we need to consider in terms of a sold methodology.

3. Symfony

Pros ORM; has a possess template engine
Cons Steep training curve

Symfony, combined by a French group SensioLabs, really feels different. It promotes regulating ORM, a and for complicated database work, and uses a possess Twig template engine, also combined by SensioLabs.

Version 2 Symfony has good facilities such as a ‘bundle’ judgment and database connectivity around Doctrine

To get a feel, conduct to, a chronicle 2 site. Don’t get confused with a chronicle 1 site,; chronicle 2 is a one to learn!

There isn’t an apparent MVC vernacular within Symfony, yet it does many a same thing as a other frameworks. It has a singular judgment called Bundles, collections of associated formula or files that assistance apart web app features. Like Zend, formula era plays an critical partial in Symfony.

This is a many formidable horizon to grasp, yet with good village support, assistance is never distant away. The indication structure is opposite to many other frameworks: it promotes Doctrine as a entrance indicate for a business proof indication code.

4.  Zend

Pros Good corporate program with longevity
Cons Design settlement concepts take time to grasp

Created by Zend, a organisation behind a PHP engine, it was apparent this horizon would be taken seriously. Zend has a facilities of a robust, corporate character program as good as associated blurb products such as a blurb web server, support and a possess IDE. In multiple these make it a absolute proceed to rise web apps.

Zend is identical to CodeIgniter and CakePHP, yet complicated support formed on settlement settlement concepts can make it tough to get started with.

Zend is almost a many sought after horizon when looking during PHP-related pursuit descriptions, and has utterly a few good facilities within it. The Lucene hunt underline brings blurb class web hunt to an app; other highlights embody form creation, information filtering and Internationalisation. But Zend is many some-more than a PHP framework; we advantage from a support, training, acceptance and associated products.

Zend isn’t only a PHP horizon – we also get support, training, acceptance and associated products

Choosing a framework

Picking your horizon can mostly count on plan circumstances, and as with any apparatus is a personal philosophical choice. A one male group competence wish a discerning turnaround with a brief training curve; a vast organisation competence cite clever program that has a feel of Java – criteria Zend will meet.

Longevity is an critical factor. It relates closely to documentation; frameworks with a prolonged story have a larger pool of knowledge. Cost competence also be an issue: frameworks with steeper training curves, such as Zend or Symfony, will need learned coders – that always means aloft wages. Commercial support is mostly indispensable for vast projects; Zend or Symfony are good placed to take a spot.

As mentioned above, if you’re seeking a career in PHP coding, Zend is a critical horizon companies are seeking for. This competence also be fuelled by a fact that ecommerce height Magento utilises Zend as a underlying structure.

For bespoke apps, it’s mostly formidable to consider because we wouldn’t use a framework. However, there competence be a few exceptions:

  • You wish a site to take advantage of skinning/ themes so we can simply rise ubiquitous sites, in that box WordPress is a good claimant to use.
  • You competence not wish a con of traffic with third-party bugs in frameworks. There competence also be too many neglected automagic behaviour.

The list subsequent shows we some of a facilities any of a 4 critical frameworks have to assistance we confirm that is a right one for your project:

Frameworks in ubiquitous yield a plain education in formulating bespoke web apps from scratch. However, PHP frameworks can mostly get confused with CMS systems such as Joomla, WordPress or Drupal; they yield a prepared done height for calm government that we can also supplement bespoke facilities to.

People mostly ask either changing from one horizon to another is an easy task. In short, emigration from one horizon or indeed from a CMS complement is homogeneous to a finish site rewrite. Even yet they all occupy an MVC architecture, any framework’s interpretation and truth is almost different.

Other technologies

All PHP frameworks should never be standalone. Integration with third-party program needs to be taken into consideration. It’s satisfactory to contend that a bigger a PHP horizon a harder this is to do.

Incorporating JavaScript libraries/frameworks is generally straightforward; it some-more or reduction involves a frontend. All a PHP frameworks have supporter functions for including JavaScript and CSS files. At a other finish of a scale, we can only embody a library as a true script tab in a HTML.

PHP frameworks are also versed to hoop many of a common confidence issues such as XSS (access vulnerability), XSRF (load a antagonistic page) and SQL injection (steal data). And when it comes to SEO, all a frameworks have structures built in to understanding with mandate such as URL re-writing. Note that speed is a cause for SEO and a distance of a horizon needs to be considered.

Finally, when meditative about cloud computing/ hosting, vast frameworks such as Zend or Symfony should be factored in when purchasing servers.


In many cases, frameworks move a assisting palm to any project. But as with any tool, how many they can assistance really many depends on a circumstances.

If your site involves some-more content, Drupal or WordPress competence be a improved fit. If you’re building a subsequent Twitter to launch ASAP, CodeIgniter or CakePHP would be good choices. If your sourroundings is corporate, afterwards Zend or Symfony competence fit best.

Finally – if we feel we need to emanate a bespoke framework, get cracking: it’s indeed utterly fun!

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Leave a Comment

Comments are moderated. Please no link dropping, no keywords or domains as names; do not spam, and do not advertise!

5 + eight =