PHP + Framework + MVC CakePHP Lectures 1. What is Framework? CakePHP Lectures 2.
From CakePHP to Laravel
-
Upload
jason-mccreary -
Category
Technology
-
view
1.936 -
download
1
Transcript of From CakePHP to Laravel
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
<?phpApp::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); }}
<?phpApp::uses('Model', 'Model');!class Message extends Model {}
<?phpecho htmlspecialchars($message['Message']['message'], ENT_COMPAT, 'UTF-8');
Model Controller
View
+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)
<?phpnamespace app\controllers;!use Yii;use yii\filters\AccessControl;use yii\web\Controller;use yii\filters\VerbFilter;use app\models\LoginForm;use app\models\ContactForm;use app\models\Message;!class SiteController extends Controller { public function actionHello() { $this->layout = false;! $message = Message::find() ->where(['id' => 2]) ->one();! return $this->render('hello', [ 'message' => $message ]); }}
<?phpnamespace app\models;!use yii\db\ActiveRecord;!class Message extends ActiveRecord { public static function tableName() { return 'messages'; }}
<?phpuse yii\helpers\Html;!echo Html::encode($message->message);
Model Controller
View
+Pros and -Cons
+ Very Trim
+ Composer
+ Modern PHP OOP with namespacing
- Tight coupling between MVC
- Disorganized documentation
<?phpclass HelloController extends \Phalcon\Mvc\Controller { public function indexAction() { $message = Message::findFirst(2);! $this->view->setVar('message', $message); }}
<?phpclass Message extends \Phalcon\Mvc\Model { public function getSource() { return 'messages'; }}
<?phpecho htmlspecialchars($message->message, ENT_COMPAT, 'UTF-8');
Model
Controller
View
+Pros and -Cons
+ Very, very trim
+ Modern PHP OOP with namespacing
- Compile PHP extensions
- Disorganized documentation
<?phpclass HomeController extends BaseController { public function showHello() { $message = Hello::find(2);! return View::make( ‘message', compact(‘message') ); }}
<?phpuse Illuminate\Auth\UserTrait;use Illuminate\Auth\UserInterface;use Illuminate\Auth\Reminders\RemindableTrait;use Illuminate\Auth\Reminders\RemindableInterface;!class Hello extends Eloquent { protected $table = 'messages';}
<?phpecho htmlspecialchars($message->message, ENT_COMPAT, 'UTF-8');
Model Controller
View
+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
<?phpnamespace JMac\DemoBundle\Controller;!use Symfony\Bundle\FrameworkBundle\Controller\Controller;!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) ); }}
<?phpnamespace JMac\DemoBundle\Entity;!use Doctrine\ORM\Mapping as ORM;!/** * Message * * @ORM\Table(name="messages") * @ORM\Entity */class Message{ /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id;! /** * @var string * * @ORM\Column(name="message",
<?phpecho $view->escape($message->getMessage());
Model Controller
View
+Pros and -Cons
+ Excellent Documentation
+ Composer
+ All the Components
- Overchoice (yml, xml, twig, etc)
- Heavy use of Reflection
- Steepest Learning Curve (terminology)
Performance BenchmarksRe
ques
t Per
Sec
ond
0
125
250
375
500
Framework
Phalcon CakePHP Yii Laravel Symfony2
When to jump ship…• Lack of feature development
• Hurts more than it helps
• End of Life (CodeIgnitor?)
Performance BenchmarksRe
ques
t Per
Sec
ond
0
1,000
2,000
3,000
4,000
Framework
HTML PHP PHP + DB Phalcon CakePHP Yii Laravel Symfony2