Now we know how to install EAV tables in our install scripts. Let’s add some attributes to those scripts, shall we?
$installer = $this;
$installer->addAttribute('modulename_content', 'title', array(
'type' => 'varchar',
'label' => 'Title',
'input' => 'text',
'class' => '',
'backend' => '',
'frontend' => '',
'source' => '',
'required' => true,
'user_defined' => true,
'default' => '',
'unique' => false,
So, basically, all the action happens at the method
addAttribute() . It accepts 3 arguments. The eav type, (defined inside of
eav_entity_type, the name of the attribute, and an array of options.
Let’s go through those options.
This is the EAV type. It pertains to the tables you created. Types are int, decimal, datetime, text, and varchar.
This is the label you create for your attribute. The “display name” if you will. This is the attribute name displayed to the user.
This is the form type you use for this attributes’ input. This is the standard use of forms
This is the class appended to the attribute when it is displayed. Good for styling as well as 3rd party features that use class identifiers on the html display.
The backend model is responsible for transformation of the content into the appropriate format necessary for insertion into the database, (as well as some other things). You can find backend models in app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/.
The exact opposite of backend. It is responsible for taking the data and transforming it into something that is user friendly or store specific. For example, the frontend model would take serialized data and unserialize it.
The source is the source model responsible for populating default data into the attribute. A good example is a dropdown of US states for an address. These aren’t user defined, and are pretty much a constant, so this can be sent over via a source model for population.
Pretty simple. This is a flag to see whethher or not this attribute is required when saving an entity. True or False.
This defines whether or not this a user defined field. This flag will determine whether or not you can perform delete operations on this particular attribute from a UI perspective. Basically, if your attribute has an admin menu, this flag will determine whether or not users can delete this attribute.
This is the default value for this particular attribute. If no options are defined by the user, this default value you specify will be entered.
Whether or not this value is unique among other attributes for this entity. If set to yes, no two attributes for this entity can be the same.