Slim RedBeanPHP and Knockout
-
Upload
vic-metcalfe -
Category
Technology
-
view
2.431 -
download
2
description
Transcript of Slim RedBeanPHP and Knockout
![Page 1: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/1.jpg)
Knockout.jsWith Minimal PHPby Vic Metcalfe
![Page 2: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/2.jpg)
Minimal Framework
Slim is 3.2MBSymfony is
50MB
![Page 3: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/3.jpg)
Minimal Framework
<?php$app = new \Slim\Slim();$app->get('/hello/:name', function ($name) { echo "Hello, $name";});$app->run();
![Page 4: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/4.jpg)
Minimal ORM
RedBeanPHP is 8.8MB
Doctrine is 9.2MB
325KB
![Page 5: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/5.jpg)
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
![Page 6: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/6.jpg)
Minimal JavaScript
Knockout is 46KB
Angular is 100KB
![Page 8: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/8.jpg)
SymfonyDoctrineAngular
![Page 9: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/9.jpg)
![Page 10: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/10.jpg)
No MVC
ModelModel ViewView ControllerController
UIDomain Logic
Shou
ld
Go Shou
ld
Go
Ends Up
Ends
Up
![Page 11: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/11.jpg)
Slim: Git R’ Done
Mid
dle
ware
Mid
dle
ware
Authentication?
Caching?
Massage Input Data?
Page Generation!
Content Negotiation?
Content Negotiation?Decoratio
n?
![Page 12: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/12.jpg)
Knockout: MVVM
ModelModel
ViewView
ViewModelViewModel
How your PHP represents your data
HTML with data-bind attributes
Two way binding of data and UI
![Page 13: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/13.jpg)
The Demo
![Page 14: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/14.jpg)
Knockout is TestableJavaScript!
• ViewModel must be a class
• Sinon is helpful for testing AJAX
![Page 15: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/15.jpg)
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(); }
![Page 16: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/16.jpg)
RedBeanPHP isalmost Testable!
• Use in-memory sqlite:
public function setUp() { R::setup('sqlite::memory:'); require('seed.php'); }
public function tearDown() { R::close(); }
![Page 17: Slim RedBeanPHP and Knockout](https://reader036.fdocuments.us/reader036/viewer/2022081511/556a7819d8b42a7c758b4903/html5/thumbnails/17.jpg)
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/