Yeoman, AngularJS and PHP

I recently started playing around with Slim.php and trying to build a semi-decoupled AngularJS app with Yeoman and a php restful API. One thing I needed to be able to do was serve the PHP files, which grunt-contrib-connect doesn’t do out of the box. So instead of making connect middleware to do this, I found grunt-php, which claims to be a drop-in replacement for grunt-contrib-connect.

To make grunt-php work in a Yeoman app, it couldn’t get any easier.

  1. Install grunt-php into your yeoman app:
    
    npm install --save-dev grunt-php
    
  2. Open your Gruntfile.js and replace all instances of connect with php.

  3. In php.options, add the new property of base:"app".

I haven’t done extensive tests, but for the most part this seems to work without issue. There is likely some cleanup that could take place, middleware removed and what not, but in a pinch you get PHP files served via PHP 5.4.0+.

 

Adam Merrifield

 

Leave a Reply