No Really, It's All About You

Post on 27-Jan-2015

108 views 1 download

Tags:

description

Slides for the php|tek '09 conference comparing CakePHP, CodeIgniter, Solar and Zend Framework

Transcript of No Really, It's All About You

NO REALLY, IT’S ALL ABOUT YOU

Chris Cornuttphp|tek 2009 - Chicago, IL

ccornutt@phpdeveloper.orghttp://joind.in/207

1

Saturday, May 23, 2009

GETTING TO KNOW YOU(GETTING TO KNOW ALL ABOUT YOU...)

2

@enygmaphpdeveloper.org

joind.inatmosenergy.com

Saturday, May 23, 2009

GOOGLE TRENDS

3

PHP5: July 2004 Last PHP4: Aug 2008

Saturday, May 23, 2009

DEVELOPERS, LET’S MEET OUR FRAMEWORKS!

4

Saturday, May 23, 2009

CAKEPHPWHO LOVES YA, BABY?

5

Saturday, May 23, 2009

CAKEPHPINTRODUCTION

• “Simple is Good”

• Mental “point and click” in applications

• Lays out an example structure for you

• Works for you on two levels - websites and cli

• bake puts the “rapid” in RAD

6

Saturday, May 23, 2009

CAKEPHPWHAT’S IN THE BOX

• Access control

• Ajax integration (Prototype)

• HTML generation

• XML handling (including RSS feeds)

• Caching

• Session Handling

• Security (request filtering)

• Command-line functionality (build scaffolding/models/etc)

7

• Cookie Handling

• Email Support

• Request Handling

• Javascript Integration

• Data Pagination

• Text Manipulation

• Date/Time Support

• Inflection

Saturday, May 23, 2009

CAKEPHPRESOURCES

• Manual at CakePHP.org (aka The Cookbook)

• The Forge - project management for CakePHP applications

• The Bakery - all things CakePHP (Tutorials/Behaviors/Case Studies/Plugins/Helpers/Snippets)

• Extensions for other software like Komodo, Selenium, Firefox

• #cakephp on Freenode (irc)

• The Show - http://live.cakephp.org8

Saturday, May 23, 2009

CAKEPHPWHAT THE CRITICS SAY

• Wrappers around simple data types

• Claims of bad markup in HTML helpers

• It’s not “Enterprise Capable”

• Poor/confusing documentation

9

Saturday, May 23, 2009

CODEIGNITERSIMPLE AND SPEEDY

10

Saturday, May 23, 2009

CODEIGNITERINTRODUCTION

• Focuses on simplicity (doesn’t get in the way)

• Small, light and easy

• “Install and Go”

• Product of EllisLabs

• Originally for PHP4, changes have been made for PHP5

• Kohana is a PHP5-based fork11

Saturday, May 23, 2009

CODEIGNITERWHAT’S IN THE BOX

• Database integration

• Encryption

• Form validation

• HTML rendering

• Session handling

• Locale support

• Templating

• XML-RPC

• Zip/Compression

12

• FTP Support

• Pagination

• Image Manipulation

• Calendars

• Input/Output Filtering

• Trackbacks

• Text Formatting (Typography)

• Custom Configuration

• Language/Locale Support

Saturday, May 23, 2009

CODEIGNITERRESOURCES

• User Guide at the main site: CodeIgniter.com

• CodeIgniter Forums: CodeIgniter.com/forums

• Community Wiki: CodeIgniter.com/wiki

• Extension for Firefox (user guide)

• TextMate bundle

13

Saturday, May 23, 2009

CODEIGNITERWHAT THE CRITICS SAY

• Difficult to have any sort of “sub applications” in your code

• Lazy loading could cause overhead as libraries grow larger

• Simple included libraries lose some advanced features

• Fewer bundled libraries (no repository like the Bakery to get more)

14

Saturday, May 23, 2009

15

This one’s for you, Ed

Saturday, May 23, 2009

SOLARSTRONG AND CONSISTENT

16

Saturday, May 23, 2009

SOLARINTRODUCTION

• PHP5-only from the start

• Fully-namespaced

• Focus on structure and elegance

• Uses several enterprise development patterns

• Smaller user base, close-knit development community

Data Mapper, ServiceLocator, Query Object, Registry, Lazy Load

17

Saturday, May 23, 2009

SOLARWHAT’S IN THE BOX

• Access control

• Caching

• JSON Support

• Logging

• Markdown

• Web Services

• Input/Output Filtering

• Unit testing

18

• Documentation Generation

• Inflection

• MIME Support

• SMTP

• Database Support

• Request Handling

• Locale Support

• Registry

Saturday, May 23, 2009

SOLARRESOURCES

• Main site at SolarPHP.com

• Community Blog at SolarPHP.com/blog

• Solar Wiki at SolarPHP.org

• Solar Manual at SolarPHP.org/manual

• #solarphp on the Freenode (irc)

19

Saturday, May 23, 2009

SOLARWHAT THE CRITICS SAY

• Poor documentation

• Not enough unit testing coverage

• Different sort of structure (controller/view and model)

• Slower release cycle

• Much lower adoption

20

Saturday, May 23, 2009

ZEND FRAMEWORKYOU WANT IT? WE GOT IT

21

Saturday, May 23, 2009

ZEND FRAMEWORKINTRODUCTION

• Standards-oriented & strong

• Targets itself towards both the casual developer and Enterprise level users

• Defined control over source (CLA)

• Only MVC by convention, really a set of components (with MVC tendencies)

• Large community of developers and users22

Saturday, May 23, 2009

ZEND FRAMEWORKWHAT’S IN THE BOX

• Flex integration

• Exception handling

• Form Validation

• LDAP Interface

• OpenID

• Dojo Integration

• Unit Testing

• Translation

23

• Authentication

• Caching

• Code Generation

• Date Handling

• Feed Parsing

• Input/Output Filtering

• Google Apps Integration

• Currency formatting

• Infocard support

• MIME Handling

• PDF

• REST Interface

• Akismet Integration

• Popular Web Service Interfaces

• XML-RPC

• Progess Bar

Saturday, May 23, 2009

ZEND FRAMEWORKRESOURCES

• Main site at framework.zend.com*

• Manual at framework.zend.com/manual/en

• Quickstart at framework.zend.com/docs/quickstart

• Contributor’s wiki at framework.zend.com/wiki

• #zftalk on Freenode (irc)

* Framework site also includes: case studies, video tutorials and bug tracker

24

Saturday, May 23, 2009

ZEND FRAMEWORKWHAT THE CRITICS SAY

• Technically* not a framework

• Tries to do it all without focusing on certain strengths

• Too much object abstraction

• Loosely coupled components can force you to make links

25

* Don’t send the Zend Goon Squad for me

Saturday, May 23, 2009

THE FRAMEWORKSAT A GLANCE

26

Framework Components Helpers

CakePHP 7 12

CodeIgniter 25 21

Solar 34 49

Zend Framework 75 22

Saturday, May 23, 2009

A CLOSER LOOKINSTALL & DEVELOPMENT

27

Saturday, May 23, 2009

INSTALLATIONCAKEPHP

• Load & Go

• Change configuration options

• No need to make directories, it’s all included

• Bootstrap and front controller included

28

In /app/config:Database connections, routing, session handling, caching options, access control

Saturday, May 23, 2009

INSTALLATIONCODEIGNITER

• Dead simple

• Update configuration for your site

• Set up database connection information

• Change any autoloads you might want

29

Sets up controller, helper, model, view, etc directories for you

Libraries/components loaded for every connection - useful for things like validation or certain models

Saturday, May 23, 2009

INSTALLATIONSOLAR

• Not quite as “beginner friendly” as CakePHP/CodeIgniter for setup

• Requires some manual setup to get the ball rolling

• Unpack the libraries in one place, make the site in another

• Create directories for site/vendor/controllers & related files

30

has the “Solar System”

/www/htdocs/project/vendor/App/www/htdocs/project/vendor/External/www/htdocs/project/vendor/<Controller Name>

Saturday, May 23, 2009

INSTALLATIONSOLAR - BOOTSTRAP

31

<?phpsession_start();

set_include_path('/www/htdocs/Solar:/www/htdocs/project:/www/htdocs/project/Test:/www/htdocs/project/Test/External');

require_once('Solar.php');Solar::start('/www/htdocs/Test.config.php');$front=Solar::factory('Solar_Controller_Front');$front->display();

Solar::stop();?>

Saturday, May 23, 2009

INSTALLATIONSOLAR - CONFIG

32

<?php$config=array();$config['Solar_Uri_Action']['path']='/';$config['Solar_Uri_Public']['path']='/Test/public';$config['Solar_Controller_Front']['default']='index';

$config['Solar_Controller_Front']['classes']=array( 'Solar_App', 'Test_App');$config['Solar_Sql']=array( 'adapter' => 'Solar_Sql_Adapter_Mysql', 'host' => 'localhost', 'user' => 'dbuser', 'pass' => 'dbpass', 'name' => 'testdb');

//Done!return $config;?>

Saturday, May 23, 2009

INSTALLATIONZEND FRAMEWORK

• Similar in setup to Solar

• A “Do It Yourself ” Framework

• Unpack the framework

• Application can be built wherever

• Make a boostrap

33

Saturday, May 23, 2009

INSTALLATIONZEND FRAMEWORK - BOOTSTRAP

34

<?phpdefined('APPLICATION_PATH') or define('APPLICATION_PATH', dirname(__FILE__));defined('APPLICATION_ENVIRONMENT') or define('APPLICATION_ENVIRONMENT', 'development');

Zend_Layout::startMvc(APPLICATION_PATH . '/layouts/scripts');$view = Zend_Layout::getMvcInstance()->getView();$view->doctype('XHTML1_STRICT');unset($view);

$frontController = Zend_Controller_Front::getInstance();$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');$frontController->setParam('env', APPLICATION_ENVIRONMENT);unset($frontController);?>

Saturday, May 23, 2009

MY FIRST PAGEFROM ZERO TO “HELLO WORLD”

35

Saturday, May 23, 2009

CAKEPHPTHE CONFIG

36

<?phpclass DATABASE_CONFIG{ var $default = array('driver' => 'mysql', 'connect' => 'mysql_pconnect', 'host' => 'localhost', 'login' => 'myuser', 'password' => 'mypassword', 'database' => 'mydb' ); }

DB Config - /app/config/database.php

create table notes ( note_title VARCHAR(100), note_detail VARCHAR(200), note_owner VARCHAR(10));

Example Database Table

Saturday, May 23, 2009

<?phpclass MyController extends AppController {

var $name = 'MyController';

function index(){ $allNotes=$this->Notes->find(‘all’,

array(‘conditions’=>array(‘Notes.note_owner’=>‘ccornutt’

)) ); $this->set(array( 'title' => 'My First Controller', ‘notes’ => $allNotes ); }}?>

CAKEPHPTHE CODE

37

Controller - /app/application/controllers/my_controller.php

View - /app/views/my_controller/index.ctp<?php echo $title.”<br>\n”;foreach($notes as $v){ echo $v[‘note_title’]' '.$v[‘note_detail’];}?>

Saturday, May 23, 2009

CODEIGNITERTHE CONFIG

38

create table notes ( note_title VARCHAR(100), note_detail VARCHAR(200), note_owner VARCHAR(10));

Example Database Table

$db['default']['hostname'] = "localhost";$db['default']['username'] = "myuser";$db['default']['password'] = "mypass";$db['default']['database'] = "mydb";$db['default']['dbdriver'] = "mysql";$db['default']['dbprefix'] = "";$db['default']['pconnect'] = TRUE;$db['default']['db_debug'] = TRUE;$db['default']['cache_on'] = FALSE;$db['default']['cachedir'] = "";$db['default']['char_set'] = "utf8";$db['default']['dbcollat'] = "utf8_general_ci";

DB Config - /system/application/config/database.php

Saturday, May 23, 2009

CODEIGNITERTHE CODE

39

<?phpclass First extends Controller { function index(){

$this->library->load(‘database’);$notes=$this->db->get_where(‘notes’,

array(‘note_owner’=>‘ccornutt’));

$to_view=array(‘title’ => ’My First Controller’,‘notes’ => $notes;

); $this->load->view('first_page',$to_view); }}?>

<?php echo $title.”<br>\n”;foreach($notes as $v){ echo $v[‘note_title’]' '.$v[‘note_detail’];}?>

Controller - /system/application/controllers/FirstController.php

View - /system/application/views/first_page.php

Saturday, May 23, 2009

SOLARTHE CONFIG

40

create table notes ( note_title VARCHAR(100), note_detail VARCHAR(200), note_owner VARCHAR(10));

Example Database Table

<?php$config['Solar_Sql'][‘adapter’]=Solar_Sql_Adapter_Mysql';$config['Solar_Sql_Adapter_Mysql'] = array( 'host' => 'localhost', 'user' => 'myuser', 'pass' => 'mypass', 'name' => 'mydb',);?>

DB Config - Appname.config.php

Saturday, May 23, 2009

SOLARTHE CODE

41

<?phpclass MyApp_App_First Extends Solar_App_Base {

protected $_action_default = 'index';

function actionIndex(){$db = Solar::factory('Solar_Sql');$bind = array(‘owner’=>‘ccornutt’);$notes= $db->query(‘select * from notes where note_owner = :owner’,$bind);

$this->to_view=array(‘title’ => ’My First Controller’,‘notes’ => $notes;

); }}?>

Controller - source/example/MyApp/App/First.php

View - source/example/MyApp/First/View/index.php<?php echo $this->title.”<br>\n”;foreach($this->notes as $v){ echo $v[‘note_title’]' '.$v[‘note_detail’];}?>

Saturday, May 23, 2009

ZEND FRAMEWORKTHE CONFIG

42

create table notes ( note_title VARCHAR(100), note_detail VARCHAR(200), note_owner VARCHAR(10));

Example Database Table

; Uses an ini file instead of a .php[production]database.adapter = PDO_MYSQLdatabase.params.dbname = "mydb"database.params.username = "myuser"database.params.password = "mypass"database.params.hostname = "localhost"

DB Config - /application/configs/application.ini

Saturday, May 23, 2009

ZEND FRAMEWORKTHE CODE

43

<?phpclass IndexController extends Zend_Controller_Action { public function indexAction(){ $cfg=new Zend_Config_Ini(‘../application/app.ini’,‘production’);

$db=Zend_Db::factory($cfg->database); $result=$db->fetchAll(‘select * from notes’); $this->view->to_view=array( ‘title’=>'My First Controller', ‘notes’=>$result ); }}?>

Controller - /application/controllers/indexController.php

<?php echo $this->title.”<br>\n”;foreach($this->notes as $v){ echo $v[‘note_title’]' '.$v[‘note_detail’];}?>

View - /application/views/scripts/index/index.phtml

Saturday, May 23, 2009

COMPARING THE FIRST STEPS

44

FrameworkSteps to Install*

Steps to “First Page” Total Steps

CakePHP 2 3 5

CodeIgniter 2 2 4

Solar 5 3 8

Zend Framework 4 2 6

* Install can include: unpacking, creating directories and making changes to configuration files.

Saturday, May 23, 2009

45

HOW FRIENDLY IS YOUR FRAMEWORK?

C’MON, SHOW US THE LOVE

Saturday, May 23, 2009

CAKEPHPWANTS TO BE YOUR FRIEND

• Installation’s as easy as one, two....well, just two

• Code-based database relationships help keep things straight

• CLI app of schemas, db dumps and migrations

• Naming conventions keep you out of trouble

46

hasMany, hasOne, belongsTo, hasAndBelongsToMany

Saturday, May 23, 2009

CODEIGNITERWANTS TO BE YOUR FRIEND

• Lazy loading lets you chose when & what

• Libraries = add, hooks = change, custom core = replacing

• Keeps you safe with URI restrictions and super-global resets

• Easy upgrading (over-write)

47

Saturday, May 23, 2009

SOLARWANTS TO BE YOUR FRIEND

• Solar System (cli) gets you up and running fast

• Easy to develop on and for

• Friendly wiki manual keeps the community keep up-to-date

48

Saturday, May 23, 2009

ZEND FRAMEWORKWANTS TO BE YOUR FRIEND

• It loves giving you just what you need

• Customizable everything

• Plays well with others

• It has plenty of other friends out there to help you out (over 10 million and counting)

49

Saturday, May 23, 2009

WANNA KNOW WHAT I THINK?

50

DISCLAIMER: THESE SUGGESTIONS ARE BASED ON MY PERSONAL EXPERIENCE, ARTICLES, RANDOM PEOPLE ON THE STREET AND A FEW OTHER BLOGS OUT THERE. THEY MIGHT HAVE BEEN MAKING IT UP FOR ALL I KNOW, BUT THAT’S A

RISK I’M WILLING TO TAKE. AFTER ALL, OPINIONS ARE LIKE...WELL, YOU KNOW. THAT BEING SAID, ENJOY THE LIST!

Saturday, May 23, 2009

WANT A ROCK SOLID, WELL DEVELOPED FRAMEWORK THAT ISN’T GOING

ANYWHERE? GO ZEND.

• Standards for the code (CLA)

• Emphasis on strong, well-planned, well-tested code

• Large component base

• Zend as a backer (corporate)

• Strong developer community/strong user community

• Grown exponentially in just a few years51

Saturday, May 23, 2009

NEW TO THE WHOLE MVC THING & WANT A FRAMEWORK TO HOLD YOUR HAND? CODEIGNITER’S THE WAY TO GO

• Does what you need without getting in the way

• User guide offers easy, complete documentation

• Pre-provided structure helps you get a handle on where each part of MVC ends up

• Helpful, active community (forums/wiki)

52

Saturday, May 23, 2009

LOOKING FOR POWER WITHOUT A LOT OF THE HASSLE? CAKEPHP’S YOUR GUY

• Friendly framework with helpful hints

• Pre-built structure let’s you hit the ground running

• Solid base components/tools

• Command-line rounds out feature set

53

Saturday, May 23, 2009

WANT SOMETHING TO APPEAL TO THE PLANNER INSIDE THAT NEEDS BOTH POWER & STRUCTURE? SHINE A LIGHT ON SOLAR

• Strong and standardized

• Similar interfaces found through out the code

• Uses well-practiced (enterprise) design patterns

• Command line builds project structures

54

Saturday, May 23, 2009

55

THAT’S ALL, GO HOMEJUST KIDDING, YOU CAN STAY FOR THE Q&A

Saturday, May 23, 2009

ADDITIONAL INFORMATION

Frameworks:CakePHP - cakephp.orgCodeIgniter - codeigniter.orgSolar - solarphp.comZend Framework - framework.zend.com

56

Contact Information:ccornutt@phpdeveloper.org@enygma

Joind.inhttp://joind.in/207

Atmos Energyhttp://atmosenergy.com

PHPDeveloper.orghttp://phpdeveloper.org

Saturday, May 23, 2009