Versions Compared

Key

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

In this article you learn how to create custom data with lists in the backend lists and forms for admins to manage custom datait. 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.

Note: Upgrade to CB 3.3.3 (Wordpress/Joomla) or CB 3.3.12 (Magento 2) to make use of the properties (described below). Naming of KenedoProperty settings have changed (old names are upward-compatible) and the documentation uses the new names only.

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.

...

You see that all link URLs are done using KLink::getRoute(). As parameter you supply a URI starting with index.php and you append a query string. option=com_configbox is fixed, controller=adminlogos instructs the system to use the controller (we create this in the next step). The query string parameter ‘task‘ would instruct which task to execute - ‘display’ is the default task if you omit it.

Create a controller

All browser HTTP requests go through controllers. The KenedoController base class has generic methods for tasks like ‘display’, ‘edit’, ‘store’, ‘delete’ etc.

...

For more details about the controllers, please refer KenedoController.

Create a model

Model is responsible to handle all the database operations. As mentioned in the above controller, we should create a model class in the following path:

...

For more details about the models, please refer KenedoModel. Properties are described in KenedoProperty.

Create a DB update script to create a table

With your model’s properties in place, you create the database table using an update script. It will be executed automatically by the Kenedo platform (during app initialisation on Joomla and WP, during setup:upgrade on M2).

...

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.

Create the views

The views responsible to render the listing and form should be created in this step. We have to create 2 views as mentioned in the controller - one for displaying a list of record, the other for an edit form.

For more details about the views, please refer KenedoView.

Creating view for the list

The following files are needed to create the list view:

...

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

class ConfigboxViewAdminlogos extends KenedoView {

	public $component = 'com_configbox';
	public $controllerName = 'adminlogos';

	/**
	 * @return ConfigboxModelAdminlogos
	 * @throws Exception
	 */
	function getDefaultModel() {
		return KenedoModel::getModel('ConfigboxModelAdminlogos');
	}

	function getPageTitle() {
		return KText::_('Logos');
	}

}

Creating view for form

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

...

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

class ConfigboxViewAdminlogo extends KenedoView {

	public $component = 'com_configbox';
	public $controllerName = 'adminlogos';

	/**
	 * @return ConfigboxModelAdminlogos
	 */
	function getDefaultModel() {
		return KenedoModel::getModel('ConfigboxModelAdminlogos');
	}

	function getPageTitle() {
		return KText::_('Logo');
	}

}

Verify the output

After creating the files and code as per the above instructions, we should be able to see the following:

  1. Menu added to the backend

  2. Upon clicking the menu, a listing of all the logos can be seen

  3. By clicking one of the logos, we can edit the details of that logo

  4. We can add a new logo by clicking the Add button

...

Further reading