Closed emjayess closed 12 years ago
I've gone down the path whereby you extend the $response
class by mixing in your own functionality. The OO purists will laugh but as a lightweight alternative to inheritance this works well.
No clue what the mustache API is but you'd do something like
<?php
//Early on..
respond(function ($request, $response) {
//Instantiate $mustache
$response->renderTemplate = function ($tmpl, $locals) use ($mustache) {
return $mustache->render($tmpl, $locals);
};
});
//Later..
respond('/', function ($request, $response) {
$response->renderTemplate('index.mustache', array('foo' => 'bar'));
});
for a tiny proof of concept project, I cobbled together a little "unframework"/microframework... I started out with vanilla php and mustache for templating, then decided to pull in klein for it's lightweight routing...
the long and short of it is that now I'm just echoing
$mustache->render()
calls in klein'srespond()
callbacks... and not using either the $response object or$response->render()
at all. I'm fishing for a better path, where I might be able to continue leveraging mustache's logicless language-agnostic templates, while also gaining the benefits of the klein $response api.thoughts? snide remarks?