In this talk we explore the pros and cons of some of the most popular PHP frameworks by comparing the code required to build the exact same application. The frameworks cover in this talks are: Zend, CakePHP, CodeIgniter and Symfonyby.
2. • Slides and code will
be posted on the
meetup group
• Video will be posted
on:
achievers.com/tech
• Tell your friends!
3. About Me
• Dev Team Lead @ Achievers
• Professional Web Framework Experience:
– J2EE with Spring, Hibernate
– PHP with CodeIgniter
– Ruby on Rails
• Not an expert in Zend Framework, CakePHP or
Symfony
4.
5.
6. Goal
1. Give you “flavor” of a few frameworks
2. Share some scientific and subjective
comparisons
3. Make you better equipped to compare and
choose the right framework
7. What I’m not doing…
• In-depth framework code walkthrough of all
features and functions
• Handing you a silver bullet
8. Agenda
1. Overview of frameworks
2. Review basic concepts
– MVC, ORMs
3. The application
– requirements, db schema
4. Code walkthrough
5. Performance and other comparisons
6. Final thoughts
11. “You can write shitty code in any
language, any framework”
12. Review - MVC
Source: http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
• Most web frameworks
are MVC these days
• Lots of inconsistencies
with the “model” layer
HTTP Request
HTML
Business Logic
& DB Access
13. Review - ORM
• Object Relational Mapping
• Maps database records to objects
• 1-to-1 table to object class
– E.g. job table -> job class
• Layer of abstraction to:
– Make code more maintainable
– Enable stronger OO programming
class TechTalk{ }
table:
tech_talk
O
R
M
15. The Application
• A basic job board where people can:
– Add jobs
– View a listing of jobs
– Look at a post in more detail
• So simple, you could probably code it in your
sleep
17. Setup
1. Download
framework *
2. Configure your app
with your db
3. Point your web
server to the
directory (i.e. vhost
in apache)
4. Start coding
18.
19. Zend Code Summary
• Nice command line tools -> less typing
• Hard object instantiations play nice with IDE
• Good, OO separation of layers, including db
access, business logic, and forms
• Cons: We’ll discuss later ;)
20.
21. CI Code Summary
• Super lightweight
• Very few conventions or “magic”
– Doesn’t force things on you
– Very explicit
• Lots of well documented tools and libraries
22.
23. CAKE Summary
• Rails-like convention over configuration
• Very powerful, with convenient tools like
scaffolding and strong relational mapping
• Lots of “magic” that you need to be aware of
-PHP Developers? -Experience with Zend, Cake, CodeIgniter, RoR, J2EE frameworks?-Had to choose a web framework for your company
Choosing a web frameworkis a lot like this. Claims to be:More enjoyable to useBetter securityBetter layers of separation
ZendRun by Zend technologiesCakeStarted in 2005Modeled on RoRIn 2009, some members left to start the Lithium framework
All frameworks “work” and have their benefitsThe reality is that
Poll audience -> what things do you look for
MySQLUsually would use singular labels for table nameInts, varchars, and datetime
Zend topics to cover:Zend command line utilities (zf)zf create project jobs_zendModel layerDifference between model and db_tablezf create model xzf create db-table job jobs (or create test)db tabledb table objects have built in functions and are 1-to-1 to tables (but not necessarily an orm). Simple DAOs. Override variables that define table, primary, and other options.Can write custom “queries” in db table objectsModelsMeant to encapsulate business logicDon’t extend anythingStrong object declaration makes for good IDE experienceIntroduce skinny controller, fat model ControllerIndex Contoller is defaultNaming conventions -> xAction, and url patterns -> not that cleanViewsBasic manipulation of dataSide notes:-good separation of staging, production, etc. out of the box
Go to wikipedia framework comparisons if you want more
AbstractionJavascript and html abstraction can lead to problems, working around framework to get what you wantQuery abstraction from ORM should be used with cautionTradeoffsRAD frameworks with lots of magic have their benefits, but also abstract devs from underlying performance issuesLite frameworks offer great performance, but you need to develop your own standards, especially for your own teamsBreakout-For almost any serious application, you’ll need to change or modify something about the framework-At Achievers, we needed to modify CI routing, logging, application loading, security filtering, etc. Understand the extendability of your applicationStay curiousLook under the covers always, and don’t be scaredUnderstand what’s happening behind the scenesUltimately, it’s the developer, not the framework