oxContentList class via the oxcontentlist::_loadMenue() method. You must override this method within the scope of the module. In order to do so, create a new file at /oxid/modules/my_cms/my_cms_oxcontentlist.php and add the following code to it.
<?php
class my_cms_oxContentList extends my_cms_oxContentList_parent
{
protected function _loadMenue( $iType, $sSQLAdd = null )
{
if($iType == 1) {
$sSQLAdd .=" and my_parentident = ''";
}
parent::_loadMenue($iType, $sSQLAdd);
}
}
?>
my_cms_oxContentList doesn't directly extend oxContentList; instead, it extends my_cms_oxContentList_parent. This is the recommended method of extending OXID classes, as it allows numerous modules to be created and inter-linked from the same base class. Internally, OXID will automatically generate transparent classes using the following structure:
my_cms_oxContentList extends my_cms_oxContentList_parent { }
my_cms_oxContentList_parent extends oxContentList { }
$iType can have the values 0, 1, 2 or 3, depending on whether the CMS component is a snippet, main menu item, category, or manual define, respectively. The if() conditional test is used to get only data sets that don't have a parent (for CMS components defined as main menu items). Therefore, the CMS sub-menu component Test 1.1 will not appear in the main menu.
oxcontentlist => my_cms/my_cms_oxcontentlist
/oxid/modules directory and without the .php extension (see Figure 6). If there were more modules using the class oxContentList, they would be appended to the right list and separated with an ampersand (&), as below:
oxcontentlist => my_cms/my_cms_oxcontentlist&my_test/test
Click here for larger image
Figure 6. OXID eShop Administration: Adding a Custom Module
content.php, using the following code:
<?php
class my_cms_Content extends my_cms_Content_parent
{
public function render()
{
$this->_sThisTemplate = parent::render();
$sSelect = "select oxid from oxcontents
where my_parentident = '".$this->getContent()->oxcontents__oxloadid->value."'";
$rs = oxDb::getDb()->Execute($sSelect);
if($rs != false && $rs->RecordCount() > 0) {
$aChilds = array();
while(!$rs->EOF) {
$oContent = oxNew("oxcontent");
$oContent->load($rs->fields[0]);
$aChilds[ ] = $oContent;
$rs->MoveNext();
}
$this->_aViewData['aChilds'] = $aChilds;
}
return $this->_sThisTemplate;
}
}
/oxid/modules/my_cms/my_cms_content.php.
oxDb::getDb(). The query retrieves all CMS components whose MY_PARENTID corresponds to the OXLOADID of the current component. This produces a resultset containing all the sub-menu items of the current main menu item. A while() loop is then used to initialize new oxContent objects, load them with data, and then write them into the array $aChilds. The array is then made available to the view as a template variable.
oxContent objects in the output template. Open the template file content.tpl and insert the following code under the line <div class="box">:
[{if $aChilds}]
<div style="border:1px solid #ccc">
Submenu:<br />
[{foreach from=$aChilds item=oContent}]
<a href="[{ $oViewConf->getSelfLink() }]cl=content&tpl=[{$oContent->oxcontents__oxid->value}]">
- [{$oContent->oxcontents__oxtitle->value}]</a><br />
[{/foreach}]
</div>
<br />
[{/if}]
content => my_cms/my_cms_content
Click here for larger image
Figure 7. OXID eShop Administration: Adding a Custom Module
Click here for larger image
Figure 8. OXID eShop: The Main Menu with Child Menus Displayed
| Andreas Ziethen, executive director of the anzido GmbH Dortmund, has been involved, as OXID Premium Solution Partner, in the implementation of shop projects based on the OXID eShop-Software since 2003. He acts as trainer within the OXID Academy and offers seminars, workshops and consulting for PHP, in particular, the OXID eShop. to e-mail him. |