entity_get_controller Fatal error entity_get_controller() is giving me an error when I try to use a class. This class is defined in another file called ingredient.controller.inc


  Fatal error:  Class name must be a valid object or a string


The following code doesn't work:

 function ingredient_add() {  
   $ingredient = entity_get_controller('ingredient')-&gt;create();
   return drupal_get_form('ingredient_add_form',$ingredient);
 }


The following one works;

function ingredient_add() {  
  $ingredient = (object) array('iid' =&gt; '','name' =&gt; '',);
  return drupal_get_form('ingredient_add_form',$ingredient);
}


The class code is the following one:

class IngredientController extends DrupalDefaultEntityController {

    public function create() {
      return (object) array(
        'iid' =&gt; '',
        'name' =&gt; '',
      );
    }
}

function nutrition_entity_info() {
  $return['ingredient'] = array (
    'label' =&gt; t('Ingredient'),
    'controller class' =&gt; 'IngredientController',
    'base table' =&gt; 'ingredient',
    'uri callback' =&gt; 'ingredient_uri',
    'fieldable' =&gt; TRUE,
    'entity keys' =&gt; array (
      'id' =&gt; 'iid',
      'label' =&gt; 'name',
    ),
    'static cache' =&gt; TRUE,
    'view modes' =&gt; array (
      'full' =&gt; array (
        'label' =&gt; t('Full content'),
        'custom settings' =&gt; FALSE,
      ),
      'teaser' =&gt; array(
        'label' =&gt; t('Teaser'),
        'custom settings' =&gt; FALSE,
      ),
    ),
  );

  return $return;
}


Do you have any idea?

Should the implementation of hook_entity_info() be nutrition_entity_info() or ingredient_entity_info()?

Nutrition is the module name, ingredient the entity I am creating.



There was some kind of typo on the code, as it seems to work now.
I suspect that you haven't implemented hook_entity_info(), which is why entity_get_controller() returns nothing, and you can't call a method of nothing.

The Examples project has an issue in the queue for an entity example. Give it a read. :-)

Hooks have the module name, so if the module is called nutrition, you'd declare nutrition_entity_info().