Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-09T20:25:06.333Z
Answers.Text: 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
Answers.UserDisplayName: Seán O'Grady
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-09T21:04:46.307Z
Answers.Text: Updated. The transformer class needs to be in the Craft namespace.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-09T20:16:44.027Z
Answers.LastActivityDate: 2015-10-09T21:04:12.757Z
Answers.LastEditDate: 2015-10-09T21:04:12.757Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Tags: <php><plugin-elementapi>
Title: How do I create an external transformer class when using the ElementApi plugin?
ThreadText: # 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
  
  ```
  <?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.
  
  **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**
  
  ```
  <?php
  namespace Craft;
  
  require_once craft()->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**
  
  ```
  <?php
  namespace Craft;
  
  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,
          ];
      }
  }
  
  ```
  
  > **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.  
  
  ---
  
  