Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In this article you learn how to create backend lists and forms for admins to manage custom data. You will learn how a controller, model, list view and form view play together and how to write the classes and templates for each. This is described in a step-by-step tutorial and on the sub-pages you find detailled information of each concept.

Important note: Upgrade to CB 3.3.3 (Joomla and Wordpress) or CB 3.3.12 (Magento 2) to make use (KenedoProperty setting names have been improved).

Create a menu in the backend

The left-hand side menu in CB is handled by the view adminmainmenu. By way of template overrides, we add a link to the list view we will create. You find the original template in {{APPLICATION_DIR}}/views/adminmainmenu/tmpl/default.php. For practical reasons, the default template loads another template named extra_menu_items.php, which is meant for additions to the menu without the need to override the entire menu.

...

Code Block
languagephp
<?php
defined('CB_VALID_ENTRY') or die();

class ConfigboxModelAdminlogos extends KenedoModel {

	function getTableName() {
		return '#__configbox_external_logos';
	}

	function getTableKey() {
		return 'id';
	}

	function getPropertyDefinitions() {

		$propDefs = array();

		$propDefs['id'] = array(
			'name'=>'id',
			'type'=>'id',
			'default'=>0,
			'label'=>KText::_('ID'),
			'listingcanSortBy'=>10000>true,
			'orderpositionList'=>10000,
			'positionForm'=>10000,
		);

		$propDefs['title'] = array(
			'name'=>'title',
			'label'=>KText::_('Title'),
			'type'=>'translatable',
			'stringTable'=>'#__configbox_strings',
			'langType'=>1053,
			'required'=>1>true,
			'listinglinkmakeEditLink'=>1>true,
			'component'=>'com_configbox',
			'controller'=>'adminlogos',
			'listingcanSortBy'=>20000,
			'orderpositionList'=>20000,
			'positionForm'=>20000,
		);

        $propDefs['file'] = array (
            'name'=>'file',
            'label'=>KText::_('Logo File'),
            'type'=>'fileimage',
            'appendSerial'=>1>true,
            'allowedExtensions'=>array('jpg', 'jpeg', 'png', 'gif'),
            'allowallowedMimeTypes'=>array('image/jpg', 'image/png', 'image/gif'),
            'required'=>0>false,
            'sizemaxFileSizeKb'=>'500000'>2000,
            'dirBase'=>KenedoPlatform::p()->getDirDataStore().'/public/custom_media/logos',
            'urlBase'=>KenedoPlatform::p()->getUrlDataStore().'/public/custom_media/logos',
            'options'=>'SAVE_FILENAME',
            'positionForm'=>400>30000,
        );

        return $propDefs;

	}

}

...

Code Block
languagephp
<?php
defined('CB_VALID_ENTRY') or die();

$db = KenedoPlatform::getDb();

if (ConfigboxUpdateHelper::tableExists('#__configbox_external_logos') == false) {
  
	$query = "
	CREATE TABLE `#__configbox_external_logos` (
	  `id` INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
	  `title` VARCHAR(127) NOT NULL DEFAULT '',
	  `file` VARCHAR(127) NOT NULL DEFAULT ''
	) ENGINE InnoDB
	";
	$db->setQuery($query);
	$db->query();

}

Note: The property ‘title’ (type translatable) stores itself in a separate table (configbox_strings) and does need a column in the base table.

Execution of database scripts are maintained by the configbox_system_vars table. The last executed version is noted down in this table. For more details about the execution procedure, please refer to the article about Application Update Scripts.

...

The following files are needed to create the list view:

{{CUSTOMIZATION_DIR}}/views/adminlogos/tmpl/default.php

...

Code Block
<?php
defined('CB_VALID_ENTRY') or die();
require(KPATH_LISTING_TMPL);

{{CUSTOMIZATION_DIR}}/views/adminlogos/metadata.xml

...

Code Block
<?xml version="1.0" encoding="utf-8"?>
<metadata>
	<view hidden="true" />
</metadata>

{{CUSTOMIZATION_DIR}}/views/adminlogos/view.html.php

...

The following files are needed to create the form view. It follows the same principles as the list view.

{{CUSTOMIZATION_DIR}}/views/adminlogo/tmpl/default.php

Code Block
<?php
defined('CB_VALID_ENTRY') or die();
require(KPATH_DETAILS_TMPL);

{{CUSTOMIZATION_DIR}}/views/adminlogo/metadata.xml

Code Block
<?xml version="1.0" encoding="utf-8"?>
<metadata>
	<view hidden="true" />
</metadata>

{{CUSTOMIZATION_DIR}}/views/adminlogo/view.html.php

...