Upload
vic-metcalfe
View
2.437
Download
2
Embed Size (px)
DESCRIPTION
Slides from the talk at http://www.meetup.com/GTA-PHP-User-Group-Toronto/events/151672182/ Source code for the demo at https://github.com/zymsys/Slim-RedBeanPHP-KnockoutJS
Citation preview
Knockout.jsWith Minimal PHPby Vic Metcalfe
Minimal Framework
Slim is 3.2MBSymfony is
50MB
Minimal Framework
<?php$app = new \Slim\Slim();$app->get('/hello/:name', function ($name) { echo "Hello, $name";});$app->run();
Minimal ORM
RedBeanPHP is 8.8MB
Doctrine is 9.2MB
325KB
Minimal ORM
$post = R::dispense('post');$post->text = 'Hello World';
$id = R::store($post); //Create or Update$post = R::load('post',$id); //RetrieveR::trash($post); //Delete
Minimal JavaScript
Knockout is 46KB
Angular is 100KB
Minimal JavaScript
SymfonyDoctrineAngular
No MVC
ModelModel ViewView ControllerController
UIDomain Logic
Shou
ld
Go Shou
ld
Go
Ends Up
Ends
Up
Slim: Git R’ Done
Mid
dle
ware
Mid
dle
ware
Authentication?
Caching?
Massage Input Data?
Page Generation!
Content Negotiation?
Content Negotiation?Decoratio
n?
Knockout: MVVM
ModelModel
ViewView
ViewModelViewModel
How your PHP represents your data
HTML with data-bind attributes
Two way binding of data and UI
The Demo
Knockout is TestableJavaScript!
• ViewModel must be a class
• Sinon is helpful for testing AJAX
Slim is Testable!
• Create your own App class
• Create an invoke method: public function invoke() { $this->middleware[0]->call(); $this->response()->finalize(); return $this->response(); }
RedBeanPHP isalmost Testable!
• Use in-memory sqlite:
public function setUp() { R::setup('sqlite::memory:'); require('seed.php'); }
public function tearDown() { R::close(); }
Thanks Y’All!
• Demo source available at: https://github.com/zymsys/Slim-RedBeanPHP-KnockoutJS
• I rarely tweet @v_metcalfe
• I even more rarely blog: http://blog.vicmetcalfe.com/