Loading Beans - Mura Docs v6

Loading Beans

One of the easiest methods of accessing a bean in Mura is using the common helper method loadBy(). All of the main Mura beans (content, user, feed, category) have this method.

For example, these main beans can be loaded using:

  • Content Bean: (optional properties: contentID, contentHistID, fileName, remoteID, title)
  • Feed Bean: (optional properties: feedID, name, remoteID)
  • User Bean (optional properties: userID, username, groupName, remoteID)
  • Category Bean: (optional properties: categoryID, name, remoteID)

How To

bean=$.getBean( {beantype} ).loadBy(
{property}={propertyValue} [ ,siteID={siteID} ]
);

What happens if a loadBy parameter has multiple matches:

If the parameters sent to a loadBy() request have more than one match then the method will return an array of beans.

For example, if the following request had more than one matches:

content = $.getBean('content');
loadByRemoteID = content.loadBy( remoteID={remoteID} );

In this case "loadByRemoteID" could be an array of contentBean objects, while the "content" variable would the contentBean in the first position of the array.

bean.getValue({Property});

This existing method can access both base bean values as well as any extended attributes. Simply pass in the variable name for the attribute and your value will be retrieved. If the value isn't found, it will return as an empty string.

Examples:

Get a common field:

value = bean.getMenuTitle();
value = bean.getValue('MenuTitle');

Get extended attribute data (see next section):

value = bean.getValue( 'yourExtendedAttributeName' );

bean.setValue({property}, {property value});

This existing method has been expanded to allow the setting of extended attributes; no more needing to figure out extend set id's, etc.

Example:

Set extended information:

bean.setValue( 'menuTitle', 'value' );

bean.save()

The save method is quite simple. If you want to save the data in the bean to the database (add or update), just call this method.

Example:

bean.save();

delete()

As long as the data is persistent, when you call this method, it will delete the associated record from the database.

Example:

bean.delete();