Answers.Body: <p>Change</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>function (EntryModel $user)
  </code></pre>
  
  <p>to </p>
  
  <pre class="lang-php prettyprint-override"><code>function (UserModel $user)
  </code></pre>
  
  <p>You were passing in a user to a function that’s expecting an EntryModel. That’s the reason for the error you are getting.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T12:56:17.247Z
Answers.Text: Thank you, Brandon and Luke. I knew I wasn't passing in the correct class... just wasn't sure what the correct usage was. This gets me back on the road!
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T05:15:55.040Z
Answers.LastActivityDate: 2015-09-22T11:45:51.790Z
Answers.LastEditDate: 2015-09-22T11:45:51.790Z
Answers.UserDisplayName: Luke Holder
Body: <p>I am attempting to use the <a href="https://github.com/pixelandtonic/ElementAPI" rel="nofollow">ElementAPI</a> to check if a user is logged in or not. I've used the ElementAPI before to check/get entries for a given section, but never for user-based entries.</p>
  
  <p>Here is my <code>elementapi.php</code> file:</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  return [
      'endpoints' =&gt; [
          'user/current.json' =&gt; [
              'elementType' =&gt; 'User',
              'criteria' =&gt; [
                  'foo' =&gt; 'bar', // Not sure what to do here.
              ],
              'transformer' =&gt; function (EntryModel $user) {
                  // Not sure about this either...
                  if ($user-&gt;isCurrent) {
                      return [
                          'status' =&gt; true
                      ];
                  } else {
                      return [
                          'status' =&gt; false
                      ];
                  }
              },
          ]
      ]
  ];
  </code></pre>
  
  <p>I'm getting to the plugin, but It really is not happy with what I'm giving it:</p>
  
  <pre><code>Argument 1 passed to Craft\ConfigService::Craft\{closure}() must be an instance of Craft\EntryModel, instance of Craft\UserModel given
  </code></pre>
  
  <p>Pretty sure it has something to do with the criteria?</p>
  
Tags: <users><current-user><plugin-elementapi>
Title: How can I interact with Users via the ElementAPI?
ThreadText: # How can I interact with Users via the ElementAPI?
  
  (Asked by: username_0 on 2015-09-22)
  
  I am attempting to use the [ElementAPI](https://github.com/pixelandtonic/ElementAPI) to check if a user is logged in or not. I've used the ElementAPI before to check/get entries for a given section, but never for user-based entries.
  
  Here is my `elementapi.php` file:
  
  ```
  <?php
  namespace Craft;
  
  return [
      'endpoints' => [
          'user/current.json' => [
              'elementType' => 'User',
              'criteria' => [
                  'foo' => 'bar', // Not sure what to do here.
              ],
              'transformer' => function (EntryModel $user) {
                  // Not sure about this either...
                  if ($user->isCurrent) {
                      return [
                          'status' => true
                      ];
                  } else {
                      return [
                          'status' => false
                      ];
                  }
              },
          ]
      ]
  ];
  
  ```
  
  I'm getting to the plugin, but It really is not happy with what I'm giving it:
  
  ```
  Argument 1 passed to Craft\ConfigService::Craft\{closure}() must be an instance of Craft\EntryModel, instance of Craft\UserModel given
  
  ```
  
  Pretty sure it has something to do with the criteria?
  
  **Tags:** users, current-user, plugin-elementapi
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-09-22. Score: 4 | Accepted answer
  
  Change
  
  ```php
  function (EntryModel $user)
  
  ```
  
  to
  
  ```php
  function (UserModel $user)
  
  ```
  
  You were passing in a user to a function that’s expecting an EntryModel. That’s the reason for the error you are getting.
  
  > **Comments:**
  > **username_0**: Thank you, Brandon and username_1. I knew I wasn't passing in the correct class... just wasn't sure what the correct usage was. This gets me back on the road!  
  
  ---
  
  