Chapter 21. PHP API

The dmBridge PHP API is a high-level, object-oriented API for CONTENTdm® that goes far beyond the CONTENTdm® PHP API. The dmBridge PHP API expedites development by making CONTENTdm® objects easy to work with:

$col = DMCollectionFactory::getCollection("/uw");
$obj = DMObjectFactory::getObject($col, 5);

echo $obj->getMetadata("title");
echo $obj->getThumbnailURL();

if ($obj->isCompound()) {
	echo "Page 1 is titled: " . $obj->getChild(0)->getTitle();
	echo "It's in this collection: "
		. $obj->getChild(0)->getCollection()->getName();

The PHP API is not a separate component, and is not even a distinct architectural feature within the dmBridge code base. It is the code base, giving the developer access to the entire dmBridge PHP namespace, including all of the classes and functions it provides.

The PHP API is available automatically within the page templates. (The DMGenericTemplateHelper class and its subclasses are actually part of it, although they only work inside the templates.) It can also be included by other PHP scripts on the same server with code like the following:

<?php include_once("/path/to/dm/api.php"); ?>

The API documentation is included with the dmBridge distribution in the doc/php_api folder. The documentation provides a list of all methods that are publicly available in all classes. Most you will never have any reason to work with. But classes like DMObject, DMCollection, DMComment, etc. may offer some useful functionality if you need it.

As a template developer, the class you will work with the most in the templates is DMGenericTemplateHelper and its subclasses. For a list of methods available in these classes, consult the API documentation. Also, check out the sample templates for working examples of these methods in action.

When working with dmBridge code, you may find it helpful to use integrated development environment (IDE) software. This will provide features like a tabbed editor; syntax highlighting; file browser; class and method name autocompletion; and/or inline method documentation. Popular PHP IDEs include NetBeans, Eclipse, and Zend Studio. IDE choice can be quite personal and this is only a intended as a tip for those not already acquainted with PHP IDEs.