<?php
function entity_practice_entity_info(){
    $info = array();
    
    $info['project'] = array(
        'label' => t('Project'),
        'base table' => 'entity_practice_projects',
        'entity keys' => array(
            'id' => 'id',
            'label' => 'name',
        ),
        'module' => 'entity_practice',
        'entity class' => 'Entity',
        'controller class' => 'EntityAPIController',
    );
    return $info;
}
/**
 * Page callback for entity_practice menu
 */
function entity_practice_page_callback(){
    $projects = entity_load('project', array(1,2,3));
    if(!isset($projects[3])){
        $entity = entity_create('project', array('id' => 3));
        $entity->name = t('Spring House');
        $entity->description = t('Some more lipsum');
        $entity->save();
    }
    dpm($projects);
    return 'Something';
}
?>

I am trying to create an entity via entity create method but this is returning Call to undefined method stdClass::save() this error.
I want to know how to fix this. Also why it is showing stdClass when i have declared the Entity class in my info hook.

Comments

surgeonbor’s picture

I'm guessing you added these lines after you initially created the entity...

  'entity class' => 'Entity',
  'controller class' => 'EntityAPIController',

You need to clear the entity info cache (clearing all cache will take care of it), and then your entity will have the correct class.