KEMBAR78
From CakePHP to Laravel | PDF
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

From CakePHP to Laravel

  • 1.
    From CakePHP toLaravel A look at PHP Frameworks
  • 2.
  • 3.
  • 4.
    Talk about theTalk • “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 obsessedwith frameworks
  • 7.
  • 8.
  • 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.
  • 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
  • 14.
  • 15.
    Model <?php classMessage 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');
  • 17.
    +Pros and -Cons + Very, very trim + Modern PHP OOP with namespacing - Compile PHP extensions - Disorganized documentation
  • 18.
  • 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
  • 21.
  • 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 aboutperformance
  • 25.
    siege -br 100-c 10 http://phalcon.local/hello/
  • 26.
    Performance Benchmarks RequestPer Second 500 375 250 125 0 Phalcon CakePHP Yii Laravel Symfony2 Framework
  • 27.
  • 28.
  • 29.
  • 30.
    laravel cakephp yii,phalcon symfony
  • 31.
  • 37.
    When to jumpship… • Lack of feature development • Hurts more than it helps • End of Life (CodeIgnitor?)
  • 38.
    “On a longenough timeline, the survival rate for everyone drops to zero.”
  • 39.
  • 40.
  • 41.
  • 42.
    fat models skinnycontrollers
  • 43.
  • 44.
  • 45.
    why you don’tneed a framework
  • 46.
  • 47.
    Performance Benchmarks RequestPer Second 4,000 3,000 2,000 1,000 0 HTML PHP PHP + DB Phalcon CakePHP Yii Laravel Symfony2 Framework
  • 48.
  • 49.
    Let’s talk! @gonedark jason@pureconcepts.net