I am attempting to use the 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:

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?



function (EntryModel $user)


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.

  • 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!
    – Damon
    Sep 22 '15 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.