Setting up a Croogo 3 development environment

Geplaatst door Marlin Cremers op Fri, Oct 09 2015 14:14:57

In this blogpost I'll explain how to set up a Croogo 3 development environment

Set-up a barebone CakePHP application

composer create-project cakephp/app croogo-app --stability dev --prefer-source

Configure Composer

In your composer.json you need to make the following changes:

  1. Change "minimum-stability": "stable" to "minimum-stability": "dev":  
  2. Include Croogo composer require croogo/croogo 3.0.*@dev
  3. Change the post-autoload-dump so it includes the Croogo ComposerInstaller:  
  4. Run dump auto-load composer dump-autoload

Set-up CakePHP

The next thing we'll need to do is configure CakePHP. This involves loading the necessary plugins and setting up a database.

Loading the plugins

bin/cake plugin load Acl --bootstrap
bin/cake plugin load Croogo/Core --bootstrap --routes

Setting up the databse

Now you'll have to configure the database for Croogo. This can be done in the applications config/app.php file.

You can find the Croogo 3.0 schema in this Gist (raw file).

Comment-out the default root route

Your application has a default route to / in routes.php in the config directory. Comment it out so that you can use Croogo's base route.

Set-up Croogo

Create a settings file in config called settings.json with the following content:


Code along

You should be able to access Croogo using your webserver. Croogo's source code can be found in vendor/croogo/croogo

Your username will be croogo, your password will be croogo as well

If you've got any questions or suggestions leave a comment

CakePHP webservices ORM

Geplaatst door Marlin Cremers op Fri, Oct 02 2015 01:08:20

We've been working on adding support for ORM like querying of data to the CakePHP Webservice plugin by UseMuffin. This allows you to work with webservices in the quick, easy and familiar way you're used to in CakePHP without having to dive into the details of a particular web API.

In this post I'll be explaining the parts of the ORM for webservices and what they're being used for.

The folder structure

Below is the folder structure that the ORM expects parts to be in. This applies to CakePHP applications and plugins.

Contains one or more Webservices
Contains the Driver
Contains one or more Endpoints
Contains one or more Resources


The first and most important part is the Webservice. Its the bridge between the ORM and the actual API you're calling. This class is being called by the Query when data needs to be read from the service.

When data needs to be queried the Query will call the execute method which will go out to the API and fetch the necessary data. That data will then be parsed and formatted by the Webservice. When done it will return a ResultSet containing a set of Resources and the total number of results available (this will for example be used for pagination).

In the example below we create a Webservice to fetch articles from a webservice at Here you can see the articles being turned into a set of Resources and being returned by the Webservice.


namespace App\Webservice;

use App\Model\Resource\Article;
use Cake\Network\Http\Client;
use Muffin\Webservice\QueryLogger;
use Muffin\Webservice\ResultSet;
use Muffin\Webservice\WebserviceInterface;
use Muffin\Webservice\WebserviceQuery;

class ArticlesWebservice implements WebserviceInterface

    public function logger(QueryLogger $logger = null)
        return new QueryLogger();

    public function execute(WebserviceQuery $query)
        switch ($query->action()) {
            case WebserviceQuery::ACTION_READ:
                $client = new Client();
                $response = $client->get('');

                if (!$response->isOk()) {
                    return false;

                $resources = [];
                foreach ($response->articles as $article) {
                    $resources[] = new Article([
                        'id' => $article->id,
                        'title' => $article->title,
                        'body' => $article->body
                    ], [
                        'markClean' => true,
                        'markNew' => false,

                return new ResultSet($resources, $response->total);

        return false;


The next part is the Endpoint, its essentially the Table equivalent of webservice ORM. This is what you use to get data out from your webservice using the ORM. For a comprehensive guide to Endpoints you can check out the CakePHP documentation about Tables.

The following methods are currently implemented in the base Endpoint:

  • find
  • findAll
  • findList
  • get

This list will increase in size as the ORM continues to be improved. This list will eventually be removed once the webservices ORM is on par with the CakePHP ORM.

Down here is an example of an Endpoint to get articles fromt the Webservice shown in the previous example. Note that it sets the Webservice which it gets from the Driver that'll have to create as well. For a post to get you started with a Driver check out this post by David Yell.


namespace App\Model\Endpoint;

use Cake\Datasource\ConnectionManager;
use Muffin\Webservice\Model\Endpoint;

class ArticlesEndpoint extends Endpoint

    public function initialize(array $config)


The last part is the Resource, this represents the actual results returned by the API.

The example below the Resource represents the articles returned when doing a find using on the Endpoint.


namespace App\Model\Resource;

use Muffin\Webservice\Model\Resource;

class Article extends Resource


More information

If you want some more information feel free to comment on this post.