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
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)
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
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
23. +Pros and -Cons
+ Excellent Documentation
+ Composer
+ All the Components
- Overchoice (yml, xml, twig, etc)
- Heavy use of Reflection
- Steepest Learning Curve (terminology)