SlideShare a Scribd company logo
1 of 49
Download to read offline
From CakePHP to Laravel 
A look at PHP Frameworks
JMac
JMac != framework expert
Talk about the Talk 
• “Hello php[world]!” using the Top 5 frameworks 
• Code 
• Pros/Cons 
• Performance 
• Deciding on a Framework 
• Understanding the Hype Curve 
• Checking the Pulse 
• Tips for future-proofing
PHP is obsessed with frameworks
Hello php[world]!
CakePHP
Model Controller 
<?php 
App::uses('Controller', 'Controller'); 
! 
class HelloController extends Controller { 
public $uses = array('Message'); 
! 
public function index() { 
$this->layout = false; 
$message = $this->Message->findById(2); 
$this->set('message', $message); 
} 
} 
<?php 
App::uses('Model', 'Model'); 
! 
class Message extends Model { 
} 
View 
<?php 
echo htmlspecialchars($message['Message']['message'], ENT_COMPAT, 'UTF-8');
+Pros and -Cons 
+ Shallow learning curve 
+ Convention over Configuration 
+ Several built-in components and helpers 
- Not modern PHP OOP 
- Arrays for all the things! 
- Code Smells 
- No Composer (2.x)
yii
Model Controller 
<?php 
namespace appcontrollers; 
! 
use Yii; 
use yiifiltersAccessControl; 
use yiiwebController; 
use yiifiltersVerbFilter; 
use appmodelsLoginForm; 
use appmodelsContactForm; 
use appmodelsMessage; 
! 
class SiteController extends Controller { 
public function actionHello() { 
$this->layout = false; 
! 
$message = Message::find() 
->where(['id' => 2]) 
->one(); 
! 
return $this->render('hello', [ 
'message' => $message 
]); 
} 
} 
<?php 
namespace appmodels; 
! 
use yiidbActiveRecord; 
! 
class Message extends ActiveRecord { 
public static function tableName() { 
return 'messages'; 
} 
} 
View 
<?php 
use yiihelpersHtml; 
! 
echo Html::encode($message->message);
+Pros and -Cons 
+ Very Trim 
+ Composer 
+ Modern PHP OOP with namespacing 
- Tight coupling between MVC 
- Disorganized documentation
Phalcon
Model 
<?php 
class Message extends PhalconMvcModel { 
Controller 
<?php 
class HelloController extends PhalconMvcController { 
public function indexAction() { 
$message = Message::findFirst(2); 
! 
$this->view->setVar('message', $message); 
} 
} 
public function getSource() { 
return 'messages'; 
} 
} 
View 
<?php 
echo htmlspecialchars($message->message, ENT_COMPAT, 'UTF-8');
+Pros and -Cons 
+ Very, very trim 
+ Modern PHP OOP with namespacing 
- Compile PHP extensions 
- Disorganized documentation
Laravel
Model Controller 
<?php 
class HomeController extends BaseController { 
public function showHello() { 
$message = Hello::find(2); 
! 
return View::make( 
‘message', 
compact(‘message') 
); 
} 
} 
<?php 
use IlluminateAuthUserTrait; 
use IlluminateAuthUserInterface; 
use IlluminateAuthRemindersRemindableTrait; 
use IlluminateAuthRemindersRemindableInterface; 
! 
class Hello extends Eloquent { 
protected $table = 'messages'; 
} 
View 
<?php 
echo htmlspecialchars($message->message, ENT_COMPAT, 'UTF-8');
+Pros and -Cons 
+ Composer 
+ Modern PHP OOP with namespacing 
+ Good Documentation 
+ Elegant Design Patterns 
- Custom ORM and templating engine 
- Heavy use of Reflection 
- Object Registry
Symfony 2
Model Controller 
<?php 
namespace JMacDemoBundleController; 
! 
use SymfonyBundleFrameworkBundleControllerController; 
! 
class HelloController extends Controller { 
public function indexAction() { 
$message = $this->getDoctrine() 
->getRepository('JMacDemoBundle:Message') 
->find(2); 
! 
return $this->render( 
'JMacDemoBundle:Hello:index.html.php', 
array('message' => $message) 
); 
} 
} 
<?php 
namespace JMacDemoBundleEntity; 
! 
use DoctrineORMMapping as ORM; 
! 
/** 
* Message 
* 
* @ORMTable(name="messages") 
* @ORMEntity 
*/ 
class Message 
{ 
/** 
* @var integer 
* 
* @ORMColumn(name="id", 
type="integer") 
* @ORMId 
* @ORM 
GeneratedValue(strategy="AUTO") 
*/ 
private $id; 
! 
/** 
* @var string 
* 
* @ORMColumn(name="message", 
View 
<?php 
echo $view->escape($message->getMessage());
+Pros and -Cons 
+ Excellent Documentation 
+ Composer 
+ All the Components 
- Overchoice (yml, xml, twig, etc) 
- Heavy use of Reflection 
- Steepest Learning Curve (terminology)
A point about performance
siege -br 100 -c 10 http://phalcon.local/hello/
Performance Benchmarks 
Request Per Second 
500 
375 
250 
125 
0 
Phalcon CakePHP Yii Laravel Symfony2 
Framework
Frameworks are slow
deciding which framework to use
the hype curve
laravel cakephp 
yii, phalcon 
symfony
Checking the pulse
When to jump ship… 
• Lack of feature development 
• Hurts more than it helps 
• End of Life (CodeIgnitor?)
“On a long enough timeline, 
the survival rate for everyone 
drops to zero.”
future-proofing your code
learn PHP
avoid custom components
fat models skinny controllers
service objects
service objects
why you don’t need a framework
<rant>
Performance Benchmarks 
Request Per Second 
4,000 
3,000 
2,000 
1,000 
0 
HTML PHP PHP + DB Phalcon CakePHP Yii Laravel Symfony2 
Framework
</rant>
Let’s talk! 
@gonedark 
jason@pureconcepts.net

More Related Content

What's hot

Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Lorvent56
 

What's hot (20)

Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New Features
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Workshop Laravel 5.2
Workshop Laravel 5.2Workshop Laravel 5.2
Workshop Laravel 5.2
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
 
Laravel 5.4
Laravel 5.4 Laravel 5.4
Laravel 5.4
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
php[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground Upphp[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground Up
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloudphp[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel framework
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
 

Similar to From CakePHP to Laravel

symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
patter
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 
Tips
TipsTips
Tips
mclee
 

Similar to From CakePHP to Laravel (20)

symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
php.pdf
php.pdfphp.pdf
php.pdf
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Tips
TipsTips
Tips
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2
 
Php
PhpPhp
Php
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
php 1
php 1php 1
php 1
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
CakePHP
CakePHPCakePHP
CakePHP
 
Api Design
Api DesignApi Design
Api Design
 

More from Jason McCreary

More from Jason McCreary (7)

Git Empowered
Git EmpoweredGit Empowered
Git Empowered
 
BDD in iOS with Cedar
BDD in iOS with CedarBDD in iOS with Cedar
BDD in iOS with Cedar
 
Patterns, Code Smells, and The Pragmattic Programmer
Patterns, Code Smells, and The Pragmattic ProgrammerPatterns, Code Smells, and The Pragmattic Programmer
Patterns, Code Smells, and The Pragmattic Programmer
 
Cache, Workers, and Queues
Cache, Workers, and QueuesCache, Workers, and Queues
Cache, Workers, and Queues
 
21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast
 
21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast
 
Configuring WordPress for Multiple Environments
Configuring WordPress for Multiple EnvironmentsConfiguring WordPress for Multiple Environments
Configuring WordPress for Multiple Environments
 

Recently uploaded

Recently uploaded (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

From CakePHP to Laravel

  • 1. From CakePHP to Laravel A look at PHP Frameworks
  • 4. Talk about the Talk • “Hello php[world]!” using the Top 5 frameworks • Code • Pros/Cons • Performance • Deciding on a Framework • Understanding the Hype Curve • Checking the Pulse • Tips for future-proofing
  • 5. PHP is obsessed with frameworks
  • 6.
  • 9. Model Controller <?php App::uses('Controller', 'Controller'); ! class HelloController extends Controller { public $uses = array('Message'); ! public function index() { $this->layout = false; $message = $this->Message->findById(2); $this->set('message', $message); } } <?php App::uses('Model', 'Model'); ! class Message extends Model { } View <?php echo htmlspecialchars($message['Message']['message'], ENT_COMPAT, 'UTF-8');
  • 10. +Pros and -Cons + Shallow learning curve + Convention over Configuration + Several built-in components and helpers - Not modern PHP OOP - Arrays for all the things! - Code Smells - No Composer (2.x)
  • 11. yii
  • 12. Model Controller <?php namespace appcontrollers; ! use Yii; use yiifiltersAccessControl; use yiiwebController; use yiifiltersVerbFilter; use appmodelsLoginForm; use appmodelsContactForm; use appmodelsMessage; ! class SiteController extends Controller { public function actionHello() { $this->layout = false; ! $message = Message::find() ->where(['id' => 2]) ->one(); ! return $this->render('hello', [ 'message' => $message ]); } } <?php namespace appmodels; ! use yiidbActiveRecord; ! class Message extends ActiveRecord { public static function tableName() { return 'messages'; } } View <?php use yiihelpersHtml; ! echo Html::encode($message->message);
  • 13. +Pros and -Cons + Very Trim + Composer + Modern PHP OOP with namespacing - Tight coupling between MVC - Disorganized documentation
  • 15. Model <?php class Message extends PhalconMvcModel { Controller <?php class HelloController extends PhalconMvcController { public function indexAction() { $message = Message::findFirst(2); ! $this->view->setVar('message', $message); } } public function getSource() { return 'messages'; } } View <?php echo htmlspecialchars($message->message, ENT_COMPAT, 'UTF-8');
  • 16.
  • 17. +Pros and -Cons + Very, very trim + Modern PHP OOP with namespacing - Compile PHP extensions - Disorganized documentation
  • 19. Model Controller <?php class HomeController extends BaseController { public function showHello() { $message = Hello::find(2); ! return View::make( ‘message', compact(‘message') ); } } <?php use IlluminateAuthUserTrait; use IlluminateAuthUserInterface; use IlluminateAuthRemindersRemindableTrait; use IlluminateAuthRemindersRemindableInterface; ! class Hello extends Eloquent { protected $table = 'messages'; } View <?php echo htmlspecialchars($message->message, ENT_COMPAT, 'UTF-8');
  • 20. +Pros and -Cons + Composer + Modern PHP OOP with namespacing + Good Documentation + Elegant Design Patterns - Custom ORM and templating engine - Heavy use of Reflection - Object Registry
  • 22. Model Controller <?php namespace JMacDemoBundleController; ! use SymfonyBundleFrameworkBundleControllerController; ! class HelloController extends Controller { public function indexAction() { $message = $this->getDoctrine() ->getRepository('JMacDemoBundle:Message') ->find(2); ! return $this->render( 'JMacDemoBundle:Hello:index.html.php', array('message' => $message) ); } } <?php namespace JMacDemoBundleEntity; ! use DoctrineORMMapping as ORM; ! /** * Message * * @ORMTable(name="messages") * @ORMEntity */ class Message { /** * @var integer * * @ORMColumn(name="id", type="integer") * @ORMId * @ORM GeneratedValue(strategy="AUTO") */ private $id; ! /** * @var string * * @ORMColumn(name="message", View <?php echo $view->escape($message->getMessage());
  • 23. +Pros and -Cons + Excellent Documentation + Composer + All the Components - Overchoice (yml, xml, twig, etc) - Heavy use of Reflection - Steepest Learning Curve (terminology)
  • 24. A point about performance
  • 25. siege -br 100 -c 10 http://phalcon.local/hello/
  • 26. Performance Benchmarks Request Per Second 500 375 250 125 0 Phalcon CakePHP Yii Laravel Symfony2 Framework
  • 30. laravel cakephp yii, phalcon symfony
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37. When to jump ship… • Lack of feature development • Hurts more than it helps • End of Life (CodeIgnitor?)
  • 38. “On a long enough timeline, the survival rate for everyone drops to zero.”
  • 42. fat models skinny controllers
  • 45. why you don’t need a framework
  • 47. Performance Benchmarks Request Per Second 4,000 3,000 2,000 1,000 0 HTML PHP PHP + DB Phalcon CakePHP Yii Laravel Symfony2 Framework
  • 49. Let’s talk! @gonedark jason@pureconcepts.net