<p>You're getting a whitescreen because you've got some PHP syntax errors in both files. Craft isn't reporting them because those config files get loaded before Craft has had a chance to bootstrap.  The underlying errors should be recorded in your web server's error logs depending on your default server configuration.</p>

<p>Try these:</p>

<p><strong>elementapi.php</strong></p>

<pre><code>&lt;?php
namespace Craft;

require_once craft()-&gt;path-&gt;getConfigPath().'transformers/EntryInfoTransformer.php';

return [
    'endpoints' =&gt; [
        'api/articles' =&gt; function() {
            return [
                'criteria'        =&gt; [
                    'section' =&gt; 'blog',
                    'order'   =&gt; 'postDate desc',
                ],
                'elementsPerPage' =&gt; 5,
                'elementType'     =&gt; 'Entry',
                'transformer'     =&gt; new EntryInfoTransformer(),
            ];
        },
    ]
];
</code></pre>

<p><strong>EntryInfoTransformer.php</strong></p>

<pre><code>&lt;?php
namespace Craft;

require craft()-&gt;path-&gt;getPluginsPath().'elementapi/vendor/autoload.php';

use League\Fractal\TransformerAbstract;

class EntryInfoTransformer extends TransformerAbstract
{
    public function transform(EntryModel $entry){
        return [
            'id' =&gt; $entry-&gt;id,
        ];
    }
}
</code></pre>

CC BY-SA 3.0
2015-10-09T20:25:06.333Z
Just tried both files, nothing else but the code above in my files, and it still returns a blank page. I've checked the system level log files and they output issues for me, but not of the kind that I want and the last one to be logged was 2 days ago. https://www.dropbox.com/s/c958xysma589x5q/Screenshot%202015-10-09%2021.24.17.png?dl=0
Seán O'Grady
CC BY-SA 3.0
2015-10-09T21:04:46.307Z
Updated. The transformer class needs to be in the Craft namespace.
Brad Bell
CC BY-SA 3.0
2015-10-09T20:16:44.027Z
2015-10-09T21:04:12.757Z
2015-10-09T21:04:12.757Z
Brad Bell
<p>I've been trying to clean up my <code>elementapi.php</code> file, and one very important step in making it more DRY is to have reusable transformer classes. </p>

<p>But I cannot seem to get it to work, the following gives me a blank page. </p>

<p>So far in my <code>elementapi.php</code> file I have the following.</p>

<pre><code>'api/articles' =&gt; function() {
// I have also tried to place this line at the very top of the file.            
require_once craft()-&gt;path-&gt;getConfigPath().'transformers/EntryInfoTransformer.php';

            'criteria' =&gt; [
                'section' =&gt; 'blog',
                'order' =&gt; 'postDate desc',
            ],

            'elementsPerPage' =&gt; 5,
            'elementType' =&gt; 'Entry',
            'transformer' =&gt; new EntryInfoTransformer(),
        },
</code></pre>

<p>and my EntryInfoTransformer.php file has </p>

<pre><code>&lt;?php

require craft()-&gt;path-&gt;getPluginsPath().'elementapi/vendor/autoload.php';

use League\Fractal\TransformerAbstract;
class EntryInfoTransformer extends TransformerAbstract{
    public function transform(EntryModel $entry) {
        return [
            'id' =&gt; $entry-&gt;id,
        ]
    },
}
</code></pre>

<p>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 &amp; 5.6. Site runs normally otherwise.</p>

<php><plugin-elementapi>
How do I create an external transformer class when using the ElementApi plugin?
# How do I create an external transformer class when using the ElementApi plugin?

(Asked by: username_0 on 2015-10-09)

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 
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.

**Tags:** php, plugin-elementapi


---

## 1 answers

### Answer by username_1 on 2015-10-09. Score: 2 | Accepted answer

You're getting a whitescreen because you've got some PHP syntax errors in both files. Craft isn't reporting them because those config files get loaded before Craft has had a chance to bootstrap.  The underlying errors should be recorded in your web server's error logs depending on your default server configuration.
Try these:
elementapi.php
path->getConfigPath().'transformers/EntryInfoTransformer.php';

return [
    'endpoints' => [
        'api/articles' => function() {
            return [
                'criteria'        => [
                    'section' => 'blog',
                    'order'   => 'postDate desc',
                ],
                'elementsPerPage' => 5,
                'elementType'     => 'Entry',
                'transformer'     => new EntryInfoTransformer(),
            ];
        },
    ]
];

EntryInfoTransformer.php
path->getPluginsPath().'elementapi/vendor/autoload.php';

use League\Fractal\TransformerAbstract;

class EntryInfoTransformer extends TransformerAbstract
{
    public function transform(EntryModel $entry){
        return [
            'id' => $entry->id,
        ];
    }
}

> **Comments:**
> **username_0**: Just tried both files, nothing else but the code above in my files, and it still returns a blank page. I've checked the system level log files and they output issues for me, but not of the kind that I want and the last one to be logged was 2 days ago. https://www.dropbox.com/s/c958xysma589x5q/Screenshot%202015-10-09%2021.24.17.png?dl=0  
> **username_1**: Updated. The transformer class needs to be in the Craft namespace.  

---

