来源:http://trac.seagullproject.org/wiki/Modules/Cms/Api
下列是CMS API中可用的方法的列表。更多的API文档?
// following notation borrowed from the Pragmatic Programmers // static object calls indicated in standard way, eg SGL_Content::getType() // object method calls indicated by SGL_Content#myMethod()
// API according CMS v. 1.4 (update 2008-07-16)
// SGL_Attribute
SGL_Attribute::SGL_Attribute(Object $oData = null) : SGL_Attribute; SGL_Attribute::getById(Integer $id) : SGL_Attribute; SGL_Attribute#getType() : Integer; SGL_Attribute#changeType(Integer SGL_CONTENT_ATTR_TYPE_*) : Boolean; SGL_Attribute#rename(String $newName) : Boolean; SGL_Attribute#delete() : Boolean; SGL_Attribute#save() : Boolean; SGL_Attribute#getParams() : aData
// SGL_Content
SGL_Content::SGL_Content(Object $oData = null) : SGL_Content; SGL_Content::createType(String $name) : SGL_Content; SGL_Content::getById(Integer $id, Integer $version = null) : SGL_Content; SGL_Content::getByName(Integer $name) : SGL_Content; SGL_Content::getByType(String $type) : SGL_Content; SGL_Content#getLinkedContents(String $typeId = null) : aSGL_Content; SGL_Content#getType() : Integer; SGL_Content#getStatus() : SGL_CMS_STATUS_*; SGL_Content#setStatus(SGL_CMS_STATUS_* $status); SGL_Content#validate() : Boolean SGL_Content#save(Boolean $newVersion = false) : SGL_Content SGL_Content#rename(String $newName) : Boolean; SGL_Content#delete(); SGL_Content#getAttribId(String $attribName) : Integer SGL_Content#addAttribute(SGL_Attribute $oAttrib) : SGL_Content;
// SGL_Context
SGL_Context::SGL_Context(Object $oData) : SGL_Context; SGL_Context#process() : SGL_Context_*;
// SGL_Context_WebContentType
SGL_Context_WebContentType#process(Object $oData) : SGL_Context_WebContentType;
// SGL_Context_WebContent
SGL_Context_WebContent#process(Object $oData) : SGL_Context_WebContent;
// SGL_Finder
SGL_Finder::factory(String $handler) : SGL_Finder; // of type SGL_FINDER_* SGL_Finder#addFilter(String $filterName, String $filterValue) : SGL_Finder; SGL_Finder#retrieve() : Boolean; SGL_Finder#getFilters() : aFilters; SGL_Finder#getAttributeFilters() : aAttributes;
// SGL_Finder_File
// not implemented
// SGL_Finder_Contenttype
SGL_Finder_Contenttype#retrieve() : aSGL_Content;
// SGL_Finder_Content
SGL_Finder_Content#retrieve() : aSGL_Content;
// SGL_Finder_AssocContent
SGL_Finder_AssocContent#retrieve() : aSGL_Content; SGL_Finder_AssocContent#addFilter(String $filterName, String $filterValue) : SGL_Finder_Assoccontent;
{oMyCV.attributeName} // using a __get() method
SGL_Finder::factory('content')
$oRestoReview = SGL_Content::createType('RestaurantReview')
->addAttribute(new SGL_Attribute(
array('name' => 'dateEaten', 'typeId' => SGL_CONTENT_ATTR_TYPE_DATE)))
->addAttribute(new SGL_Attribute(
array('name' => 'dishName', 'typeId' => SGL_CONTENT_ATTR_TYPE_TEXT)))
->addAttribute(new SGL_Attribute(
array('name' => 'overallRating', 'typeId' => SGL_CONTENT_ATTR_TYPE_FLOAT)))
->save();
$oRestoReview = SGL_Content::getByType('RestaurantReview');
$oRestoReview->rename('Foo');
$oRestoReview->renameAttribute('bar', 'baz');
$oRestoReview->deleteAttribute('baz');
$bar = SGL_Attribute::getById($id); // never by name, too ambiguous
$bar->rename('fluux');
$bar->delete();
$bar = SGL_Attribute::getById($id); $type = $bar->getType();
// eg for a choice attrib like RADIO
$attr = SGL_Attribute::getById($id);
if ($attr->getType() == SGL_CONTENT_ATTR_TYPE_RADIO) {
$aParams = $attr->getParams();
}
$bar = SGL_Attribute::getById($id); $bar->changeType(SGL_ATTRTYPE_FLOAT);
$bar = SGL_Attribute::getById($id); $bar->value = 'new value'; $oAttrib = $bar->save();
$oRestoReview = SGL_Content::getByType('RestaurantReview');
// or by $typeId: $oRestoReview = SGL_Content::getType($typeId) $oRestoReview->dishName = 'Chicken Catchatorie'; $oRestoReview->overallRating = 7.6; $oRestoReview->save();
// pass data from post as arg $oContext = new SGL_Context($input);
//context strategy determines if Content or ContentType //and maps data correctly //SGL_Content object can be built from any input (php object, post, xml, etc) $oContent = new SGL_Content($oContext->process());
$oRestoReview = SGL_Content::getById($id); $oRestoReview->dishName = "Duck a l'Orange"; $oRestoReview->save();
$oExampleCV = SGL_Content::getById($id); print '<pre>';print_r($oExampleCV);
/*
SGL_Content Object
(
[id] => 7
[name] => simple CV example
[createdByName] => admin
[createdById] => 1
[updatedById] => 1
[dateCreated] => 2006-04-19 11:43:45
[lastUpdated] => 2006-04-19 11:43:45
[typeId] => 15
[typeName] => CV Format Simple
[aAttribs] => Array
(
[0] => SGL_Attribute Object
(
[id] => 33
[typeId] => 6
[name] => website
[alias] => Website
[value] => http://foo.com
[contentTypeId] => 15
)
[1] => SGL_Attribute Object
(
[id] => 34
[typeId] => 1
[name] => email
[alias] => Email
[value] => demian@muse23.com
[contentTypeId] => 15
)
)
) */
$oRestoReview = SGL_Content::getById($id); $oRestoReview->delete();
$aReviews = SGL_Finder::factory('content')
->addFilter('typeName', 'RestaurantReview')
->addFilter('createdBy', SGL_Session::getUid())
->retrieve();
$aReviews = SGL_Finder::factory('content')
->addFilter('typeId', 123)
->addFilter('createdBy', SGL_Session::getUid())
->addFilter('sortBy', 'field_name')
->addFilter('sortOrder', 'ASC')
->retrieve();
$aReviews = SGL_Finder::factory('content')
->addFilter('sortBy', 'name')
->addFilter('sortOrder', 'ASC')
->addFilter('limit', array('offset' => 1, 'count' => 2))
->retrieve();
$aReviews = SGL_Finder::factory('content')
->addFilter('sortBy', 'name')
->addFilter('sortOrder', 'ASC')
->addFilter('limit', array('count' => 2))
->retrieve();
$aReviews = SGL_Finder::factory('content')
->addFilter('sortBy', 'name')
->addFilter('sortOrder', 'ASC')
->addFilter('limit', 2)
->retrieve();
$aReviews = SGL_Finder::factory('content')
->addFilter('sortBy', array('attribute' => 'title'))
->addFilter('sortOrder', 'DESC')
->retrieve();
$aReviews = SGL_Finder::factory('content')
->addFilter('sortBy', 'name')
->addFilter('sortOrder', 'ASC')
->addFilter('categoryId', 6)
->retrieve();
(The operator below can be any allowable in SQL, for example: '=','<>', '<', '>', '<=', '>=', 'LIKE' or 'IN', to match a list of possible values.
Currently, when using IN, the list must be passed in the format "('value1','value2','value3')" to function properly.)
$attribFilter = array(
'name' => 'letter',
'value' => 'a',
'operator' => '='
);
$aReviews = SGL_Finder::factory('content')
->addFilter('typeName', 'Glossary term')
->addFilter('status', SGL_CMS_STATUS_PUBLISHED)
->addFilter('attribute', $attribFilter)
->retrieve();
$aReviews = SGL_Finder::factory('content')
->addFilter('typeName', 'Article')
->addFilter('attribute', array(
'name' => 'introduction',
'operator' => '=',
'value' => 'foo'))
->addFilter('attribute', array(
'name' => 'body',
'operator' => '=',
'value' => 'bar'));
$aContents = SGL_Finder::factory('assocContent')
->addFilter('typeId', SGL_CMS_CONTENTTYPE_REVIEW_PRODUCT_USER)
->addFilter('status', SGL_CMS_STATUS_PUBLISHED)
->addFilter('sortBy', 'date_created')
->addFilter('sortOrder', 'desc')
->addFilter('assocContents', array('parentId' => $contentId))
->retrieve();
$aRet = SGL_Finder::factory('assocContent')
->addFilter('sortBy', 'content_id')
->addFilter('sortOrder', 'DESC')
->addFilter('assocContents', array('childId' => 8))
// get articles only
->addFilter('typeId', 1)
->retrieve();
首先你的内容类型必须包含一个file类型的属性。然后你必须在admin管理界面上传媒体文件到相应的内容。当你想访问该媒体文件时,在你的Finder搜索中指定文件名称,如下:
$aRet = SGL_Finder::factory('content')
->addFilter('categoryId', 6)
->addFilter('mediaInfo', array('name' => 'myProfilePic'));
->addFilter('mediaInfo', array('name' => 'myProfileThumb'));
->retrieve();
然后你可以遍历结果集
foreach ($aContents as $oContent) {
// to access file name
$oContent->media->myProfilePic->file_name
// to access mime type $oContent->media->myProfileThumb->mime_type }