While playing around with AngularJS, I decided to create a simple PHP app/framework to test API handling. Here’s what I’ve used so far:
PHP Slim as back end framework. For this project, I didn’t need a user management or heavy dependency injection, but instead a solid REST API. PHP Slim lets you bootstrap smaller PHP applications very fast and is easy to learn. When I tried to receive POST data sent by AngularJS I found out, that you can’t fetch them by using
$app->request->post(), instead you have to use
json_decode($app->request->getBody(), true). Next time I should read the documentation more carefully.
Eloquent ORM. This is a core element in Laravel and very neat. I preferred this over Doctrine (would have been an overload for this project) and Propel (just wasn’t stable with PHP Slim). When using Eloquent make sure that you set either
public $timestamps = falsein your model or use
updated_atcolumns in your tables to make it run with PHP Slim. I used the second option and have to say: Eloquent rocks!
Twig. In my example app only one view is rendered by the back end so far: The main HTML template—all other views are handled via AngularJS. So why did I use Twig? I don’t know, what kind of projects I might do with this project and Twig guarantees that if in the future I want to render templates via back end, everything is prepared.
I don’t know if the structure of the project makes sense, but I will hopefully find out soon. Try it out!
Since I didn’t update the project for some time, I removed candyGular from Github.