I've been trying to clean up my elementapi.php
file, and one very important step in making it more DRY is to have reusable transformer classes.
But I cannot seem to get it to work, the following gives me a blank page.
So far in my elementapi.php
file I have the following.
'api/articles' => function() {
// I have also tried to place this line at the very top of the file.
require_once craft()->path->getConfigPath().'transformers/EntryInfoTransformer.php';
'criteria' => [
'section' => 'blog',
'order' => 'postDate desc',
],
'elementsPerPage' => 5,
'elementType' => 'Entry',
'transformer' => new EntryInfoTransformer(),
},
and my EntryInfoTransformer.php file has
<?php
require craft()->path->getPluginsPath().'elementapi/vendor/autoload.php';
use League\Fractal\TransformerAbstract;
class EntryInfoTransformer extends TransformerAbstract{
public function transform(EntryModel $entry) {
return [
'id' => $entry->id,
]
},
}
I don't get any errors, nothing in either the php or craft logs, just a blank while page. This has been tested on php 5.5 & 5.6. Site runs normally otherwise.