Create Admin Component

Create Joomla Admin Component

Skip to end of metadata

Go to start of metadata

 

 

Contents

 


 

Overview


This page has instruction  how to create joomla component

Back to top

 

Form field


Standard form field parameter

Parameter Example Description
type (mandatory) type=”text”
name (mandatory) name=”username” is the unique name of the parameter
label (mandatory) (translatable) label=”USERNAME_LABEL” is the descriptive title of the field
default (optional) (translatable) default=”0″ is the default value
description (optional) (translatable) description=”USERNAME_DESC” is text that will be shown as a tooltip when the user moves the mouse over the drop-down box
size (optional) size=”30″ is the width of the text box in characters. If omitted the width is determined by the browser
maxlength (optional) limits the number of characters that may be entered
class (optional) class=”inputbox” is a CSS class name for the HTML form field. If omitted this will default to ‘text_area’.
validate within input field
class=”required validate-email”
class=”required validate-text”
required (optional) required=”true” true / false
readonly (optional) readonly=”true” true / false
filter (optional) filter=”raw” allow the system to save certain html tags or raw data
cols (optional) cols=”30″ defines the width of the editor (in columns)
rows (optional) rows=”3″ defines the height of the editor (in rows)

Back to top

Standard form field types

Type Example XML Output Description
text <field name=”username” type=”text”
description=”DESC”  label=”LABEL”
required=”true”  size=”30″  />
provides a text box for data entry.
email <field name=”email” type=”email”
description=”DESC”
label=”EMAIL” required=”true” size=”30″ validate=”email” />
provides a text box for data entry.
url <field name=”webpage” type=”url” label=”LABEL”
description=”DESC” size=”30″ />
provides a text box for data entry.
password <field name=”password” type=”password”  autocomplete=”off”
class=”inputbox” description=”DESC”
filter=”raw”    label=”PASSWORD” size=”30″    />
provides a text box for entry of a password. The password characters will be obscured as they are entered.
textarea <field name=”description” type=”textarea”
rows=”3″ cols=”30″ label=”DESCRIPTION”
description=”DESC” />
provides a text area for entry of multi-line text.
editor <field    name=”description” type=”editor” label=”DESCRIPTION”
description=”DESC” filter=”safehtml” buttons=”true”
hide=”readmore,pagebreak”/>
provides an editor area field.
list <field name=”state” type=”list” label=”JSTATUS”
description=”DESC” size=”1″ default=”1″ >
<option value=”1″>JPUBLISHED</option>
<option value=”0″>JUNPUBLISHED</option>
</field>
provides a drop down list of custom-defined entries.
checkbox <field type=”checkbox” name=”hideprotected”    value=”1″ label=”LABEL”    description=”DESC” onclick=”this.form.submit();” /> provides a single checkbox to be checked or unchecked
checkboxes <field name=”imp_exp”  type=”checkboxes”  multiple=”yes”  description=”desc.”  label=”select”  message=”message”>
<option value=”0″>Importatore Europeo</option>
<option value=”1″>Esportatore Europeo</option>
<option value=”2″>Importatore Extra Europeo</option>
<option value=”3″>Esportatore Extra Europeo</option>
</field>
provides unlimited checkboxes that can be used for multi-select.
radio <field name=”own_prefix” type=”radio” label=”LABEL” description=”DESC”
default=”0″>
<option value=”0″>JNO</option>
<option value=”1″>JYES</option>
</field>
provides radio buttons to select different options.
hidden <field name=”asset_id” type=”hidden” filter=”unset”/> provides a hidden field for saving a form field whose value cannot be altered directly by a user in the Administrator (it can be altered in code or by editing the params.ini file).
calendar <field name=”registerDate” type=”calendar”
label=”LABEL”  description=”DESC” readonly=”true”
format=”%Y-%m-%d %H:%M:%S” size=”22″ filter=”user_utc”    />
provides a text box for entry of a date. An icon next to the text box provides a link to a pop-up calendar, which can also be used to enter the date value.
filelist <field name=”myfile” type=”filelist” default=”” label=”Select a file” description=”” directory=”administrator” filter=”” exclude=”” stripext=”” /> provides a drop down list of files from a specified directory.
imagelist <field name=”myimage” type=”imagelist” default=”” label=”Select an image” description=”” directory=”” exclude=”” stripext=”” /> provides a drop down list of image files in a specified directory.
integer <field name=”myintegeralue” type=”integer” default=”Some integer” label=”Choose an integer” description=”” first=”1″ last=”10″ step=”1″ /> provides a drop down list of integers between a minimum and maximum.
sql <field name=”myfield” type=”sql” default=”10″ label=”Select an article” query=”SELECT id, title FROM #__content” key_field=”id” value_field=”title” /> provides a drop down list of entries obtained by running a query on the Joomla Database. The first results column returned by the query provides the values for the drop down box.
media
<field name="myimage" type="media" directory="stories" />
provides modal access to the media manager for insertion of images with upload for users with appropriate permissions.
category <field name=”mycategory” type=”category” extension=”com_content” label=”Select a category” description=”” /> provides a drop down list of categories for an extension.
accesslevel <field name=”mycalendar” type=”calendar” default=”5-10-2008″ label=”Select a date” description=”” format=”%d-%m-%Y” /> provides a drop down list of viewing access levels.

Back to top

JTable check()


1. Check Empty  Field

if (empty($this->message)) {
 $this->setError(JText::_('COM_MESSAGES_ERROR_INVALID_MESSAGE'));
 return false;
}

2. check for http, https, ftp on webpage

if ((strlen($this->webpage) > 0)
&& (stripos($this->webpage, 'http://') === false)
&& (stripos($this->webpage, 'https://') === false)
&& (stripos($this->webpage, 'ftp://') === false))
{
 $this->webpage = 'http://'.$this->webpage;
}

3. SET ordering

 if ($this->state < 0) {
 // Set ordering to 0 if state is archived or trashed
 $this->ordering = 0;
}
else if (empty($this->ordering)) {
 // Set ordering to last if ordering was 0
 $this->ordering = self::getNextOrder('`catid`=' . $this->_db->Quote($this->catid).' AND state>=0');
}

4. SET alias

 if (empty($this->alias)) {
 $this->alias = $this->name;
}
$this->alias = JApplication::stringURLSafe($this->alias);
if (trim(str_replace('-','',$this->alias)) == '') {
 $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
}

5. Check the publish down date is not earlier than publish up.

 if (intval($this->publish_down) > 0 && $this->publish_down < $this->publish_up) {
 // Swap the dates.
 $temp = $this->publish_up;
 $this->publish_up = $this->publish_down;
 $this->publish_down = $temp;
}

6. Check Metakey

 if (!empty($this->metakey)) {
 // only process if not empty
 $bad_characters = array("\n", "\r", "\"", "<", ">"); // array of characters to remove
 $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey); // remove bad characters
 $keys = explode(',', $after_clean); // create array using commas as delimiter
 $clean_keys = array();
 foreach($keys as $key) {
 if (trim($key)) {
 // ignore blank keywords
 $clean_keys[] = trim($key);
 }
 }
 $this->metakey = implode(", ", $clean_keys); // put array back together delimited by ", "
}

7. Metadesc clean up description — eliminate quotes and <> brackets

 if (!empty($this->metadesc)) {
 // only process if not empty
 $bad_characters = array("\"", "<", ">");
 $this->metadesc = JString::str_ireplace($bad_characters, "", $this->metadesc);
}

8. Check any string pattern

 if (JFilterInput::checkAttribute(array ('href', $this->url))) {
 $this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL'));
 return false;
}

JTable bind()


1.Example 1

public function bind($array, $ignore = '')
{
 if (isset($array['params']) && is_array($array['params'])) {
 $registry = new JRegistry();
 $registry->loadArray($array['params']);
 $array['params'] = (string)$registry;
 }
 if (isset($array['metadata']) && is_array($array['metadata'])) {
 $registry = new JRegistry();
 $registry->loadArray($array['metadata']);
 $array['metadata'] = (string)$registry;
 }
 return parent::bind($array, $ignore);
}

2. Example 2

public function bind($array, $ignore = array())
 {
 if (isset($array['params']) && is_array($array['params'])) {
 $registry = new JRegistry();
 $registry->loadArray($array['params']);
 if((int) $registry->get('width', 0) < 0){
 $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', JText::_('COM_BANNERS_FIELD_WIDTH_LABEL')));
 return false;
 }
 if((int) $registry->get('height', 0) < 0){
 $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', JText::_('COM_BANNERS_FIELD_HEIGHT_LABEL')));
 return false;
 }
 // Converts the width and height to an absolute numeric value:
 $width = abs((int) $registry->get('width', 0));
 $height = abs((int) $registry->get('height', 0));
 // Sets the width and height to an empty string if = 0
 $registry->set('width', ($width ? $width : ''));
 $registry->set('height', ($height ? $height : ''));
 $array['params'] = (string)$registry;
 }
 if (isset($array['imptotal'])) {
 $array['imptotal'] = abs((int) $array['imptotal']);
 }
 return parent::bind($array, $ignore);
 }

 

JTable store()


 

1.Example 1

public function store($updateNulls = false)
{
 $date = JFactory::getDate();
 $user = JFactory::getUser();
 if ($this->id) {
 // Existing item
 $this->modified = $date->toMySQL();
 $this->modified_by = $user->get('id');
 } else {
 // New weblink. A weblink created and created_by field can be set by the user,
 // so we don't touch either of these if they are set.
 if (!intval($this->created)) {
 $this->created = $date->toMySQL();
 }
 if (empty($this->created_by)) {
 $this->created_by = $user->get('id');
 }
 }
 // Verify that the alias is unique
 $table = JTable::getInstance('Weblink', 'WeblinksTable');
 if ($table->load(array('alias'=>$this->alias,'catid'=>$this->catid)) && ($table->id != $this->id || $this->id==0)) {
 $this->setError(JText::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS'));
 return false;
 }
 // Attempt to store the user data.
 return parent::store($updateNulls);
}

 

JToolBar


Title Screenshot Sample Code
Title
1. JToolBarHelper::title(JText::_('COM_WEBLINKS_MANAGER_WEBLINK'), 'weblinks.png');
2. JToolBarHelper::title(JText::_($isNew ? 'COM_USERS_VIEW_NEW_LEVEL_TITLE' : 'COM_USERS_VIEW_EDIT_LEVEL_TITLE'), 'levels-add');
New
1. JToolBarHelper::addNew('weblink.add');
2. JToolBarHelper::addNew( 'phocagalleryimg.add','JTOOLBAR_NEW');
Apply
JToolBarHelper::apply('weblink.apply');
Save
JToolBarHelper::save('weblink.save');
save2new
JToolBarHelper::save2new('weblink.save2new');
save2copy
JToolBarHelper::save2copy('weblink.save2copy');
editList
JToolBarHelper::editList('weblink.edit');
publish
JToolBarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true);
unpublish
JToolBarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true);
archiveList
JToolBarHelper::archiveList('weblinks.archive');
unarchiveList
1. JToolBarHelper::unarchiveList('links.publish', 'JTOOLBAR_UNARCHIVE');
2. JToolBarHelper::unarchiveList('banners.publish');
checkin
JToolBarHelper::checkin('weblinks.checkin');
deleteList
1. JToolBarHelper::deleteList('', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH');
2. JToolBarHelper::deleteList('', 'users.delete');
3. JToolBarHelper::deleteList( 'COM_PHOCAGALLERY_WARNING_DELETE_ITEMS_AVATAR', 'phocagalleryusers.delete', 'COM_PHOCAGALLERY_DELETE');
4. JToolBarHelper::deleteList('', 'languages.delete','JTOOLBAR_EMPTY_TRASH');
trash
JToolBarHelper::trash('weblinks.trash');
preferences
1. JToolBarHelper::preferences('com_weblinks');
2. JToolBarHelper::preferences('com_media', 450, 800, 'JToolbar_Options', '', 'window.location.reload()');
help
JToolBarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS');
cancel
1. JToolBarHelper::cancel('weblink.cancel');
2. JToolBarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE');
makeDefault
1. JToolBarHelper::makeDefault('styles.setDefault', 'COM_TEMPLATES_TOOLBAR_SET_HOME');
2. JToolBarHelper::makeDefault('installed.setDefault');
custom
1. JToolBarHelper::custom('users.unblock', 'unblock.png', 'unblock_f2.png', 'COM_USERS_TOOLBAR_UNBLOCK', true);
2. JToolBarHelper::custom('mail.send', 'send.png', 'send_f2.png', 'COM_USERS_TOOLBAR_MAIL_SEND_MAIL', false);
appendButton
 1.
$bar = & JToolBar::getInstance('toolbar');
$bar->appendButton( 'Custom', '<a href="#" onclick="javascript:if(confirm(\''.addslashes(JText::_('COM_PHOCAGALLERY_WARNING_AUTHORIZE_ALL')).'\')){submitbutton(\'phocagalleryusers.approveall\');}"><span title="'.JText::_('COM_PHOCAGALLERY_APPROVE_ALL').'" type="Custom"></span>'.JText::_('COM_PHOCAGALLERY_APPROVE_ALL').'</a>');
2.
$bar = & JToolBar::getInstance('toolbar');
$bar->appendButton( 'Custom', '<a href="#" onclick="javascript:if(document.adminForm.boxchecked.value==0){alert(\''.JText::_('COM_PHOCAGALLERY_WARNING_RECREATE_MAKE_SELECTION').'\');}else{if(confirm(\''.JText::_('COM_PHOCAGALLERY_WARNING_RECREATE_THUMBNAILS').'\')){submitbutton(\'phocagalleryimg.recreate\');}}"><span title="'.JText::_('COM_PHOCAGALLERY_RECREATE_THUMBS').'" type="Custom"></span>'.JText::_('COM_PHOCAGALLERY_RECREATE').'</a>');
3.
$bar = JToolBar::getInstance('toolbar');
$bar->appendButton('Popup', 'options', 'COM_MESSAGES_TOOLBAR_MY_SETTINGS', 'index.php?option=com_messages&amp;view=config&amp;tmpl=component', 850, 400);
divider
JToolBarHelper::divider();

JToolBar Submenu


//view.html.php
public function display($tpl = null){
  $this->addSubMenu();
}
public function addSubMenu(){
 $submenu = & JToolBar::getInstance('submenu');
 $submenu->appendButton(JText::_( JText::_( 'TITLE CONTACT' ) ), 'index.php?option=com_hrm&controller=contact');
 $submenu->appendButton(JText::_( JText::_( 'TITLE CONTACT SETTING' ) ), 'index.php?option=com_hrm&controller=contact&task=setting',true);
}

 

Query  Build ( getListQuery() )


Select  fields

1.
// Select the required fields from the table.
$query->select(
$this->getState(
 'list.select',
 'a.id AS id, a.name AS name, a.alias AS alias,'.
 'a.checked_out AS checked_out,'.
 'a.checked_out_time AS checked_out_time, a.catid AS catid,' .
 'a.clicks AS clicks, a.metakey AS metakey, a.sticky AS sticky,'.
 'a.impmade AS impmade, a.imptotal AS imptotal,' .
 'a.state AS state, a.ordering AS ordering,'.
 'a.purchase_type as purchase_type,'.
 'a.language, a.publish_up, a.publish_down'
)
);
2.
// Select the required fields from the table.
$query->select(
 'a.track_date as track_date,'.
 'a.track_type as track_type,'.
 'a.`count` as `count`'
);
3.
$query->select('*');
4.
$query->select($this->getState('list.select', 'a.*'));

From

1.
$query->from('`#__banners` AS a');
2.
$query->from('#__extensions');

Join

$query->select('l.title AS language_title');
$query->join('LEFT', '`#__languages` AS l ON l.lang_code = a.language');

Where

1.
// Filter by published state
$published = $this->getState('filter.state');
if (is_numeric($published)) {
 $query->where('a.state = '.(int) $published);
} else if ($published === '') {
 $query->where('(a.state IN (0, 1))');
}
2.
// Filter by category.
$categoryId = $this->getState('filter.category_id');
if (is_numeric($categoryId)) {
 $query->where('a.catid = '.(int) $categoryId);
}
3.
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search)) {
 if (stripos($search, 'id:') === 0) {
 $query->where('a.id = '.(int) substr($search, 3));
 } else {
 $search = $db->Quote('%'.$db->getEscaped($search, true).'%');
 $query->where('(a.name LIKE '.$search.' OR a.alias LIKE '.$search.')');
 }
}
4.
// Filter by begin date
$begin = $this->getState('filter.begin');
if (!empty($begin)) {
 $query->where('a.track_date >= '.$db->Quote($begin));
}
5.
// Filter by end date
$end = $this->getState('filter.end');
if (!empty($end)) {
 $query->where('a.track_date <= '.$db->Quote($end));
}
6.
// Filter by access level.
if ($access = $this->getState('filter.access')) {
 $query->where('a.access = ' . (int) $access);
}
7.
// Filter by search in name.
$search = $this->getState('filter.search');
if (!empty($search)) {
 if (stripos($search, 'id:') === 0) {
 $query->where('a.id = '.(int) substr($search, 3));
 }
 else if (stripos($search, 'author:') === 0) {
 $search = $db->Quote('%'.$db->getEscaped(substr($search, 7), true).'%');
 $query->where('(ua.name LIKE '.$search.' OR ua.username LIKE '.$search.')');
 }
 else {
 $search = $db->Quote('%'.$db->getEscaped($search, true).'%');
 $query->where('(a.name LIKE '.$search.' OR a.alias LIKE '.$search.')');
 }
}
8.
// Filter by search in id
$search = $this->getState('filter.search');
if (!empty($search) && stripos($search, 'id:') === 0) {
 $query->where('extension_id = '.(int) substr($search, 3));
}

Order by

1.
// Add the list ordering clause.
$query->order($db->getEscaped($this->getState('list.ordering', 'a.date_time')).' '.$db->getEscaped($this->getState('list.direction', 'DESC')));
2.
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering');
$orderDirn = $this->state->get('list.direction');
if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
 $orderCol = 'category_title '.$orderDirn.', a.ordering';
}
$query->order($db->getEscaped($orderCol.' '.$orderDirn));
3.
$query->order($this->getState('list.ordering').' '.$this->getState('list.direction'));

 

Filter Data


HTML

1.
<input type="text" id="filter_search" name="filter_search">
2.
<select name="filter_published"></select>
3.
<select name="filter_category_id"></select>
4.
<select name="filter_access"></select>
5.
<select name="filter_language"></select>

Module Methode

protected function populateState($ordering = null, $direction = null)
{
 // Initialise variables.
 $app = JFactory::getApplication('administrator');
  
 1.
 $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
 $this->setState('filter.search', $search);
 2.
 $published = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_published', '', 'string');
 $this->setState('filter.state', $published);
 3.
 $categoryId = $this->getUserStateFromRequest($this->context.'.filter.category_id', 'filter_category_id', '');
 $this->setState('filter.category_id', $categoryId);
 4.
 $accessId = $this->getUserStateFromRequest($this->context.'.filter.access', 'filter_access', null, 'int');
 $this->setState('filter.access', $accessId);
 5.
 $language = $this->getUserStateFromRequest($this->context.'.filter.language', 'filter_language', '');
 $this->setState('filter.language', $language);
 // Load the parameters.
 $params = JComponentHelper::getParams('com_weblinks');
 $this->setState('params', $params);
 // List state information.
 parent::populateState('a.title', 'asc');
}
protected function getStoreId($id = '')
{
 1.
 $id.= ':' . $this->getState('filter.search');
 
 2.
 $id.= ':' . $this->getState('filter.state');
 
 3.
 $id.= ':' . $this->getState('filter.category_id');
 
 4.
 $id.= ':' . $this->getState('filter.access');
 5.
 $id.= ':' . $this->getState('filter.language');
 return parent::getStoreId($id);
}
protected function getListQuery()
{
 1.
 // Filter by search in title
 $search = $this->getState('filter.search');
 if (!empty($search)) {
 if (stripos($search, 'id:') === 0) {
 $query->where('a.id = '.(int) substr($search, 3));
 } else {
 $search = $db->Quote('%'.$db->getEscaped($search, true).'%');
 $query->where('(a.title LIKE '.$search.' OR a.alias LIKE '.$search.')');
 }
 }
 
 2.
 // Filter by published state
 $published = $this->getState('filter.state');
 if (is_numeric($published)) {
 $query->where('a.state = '.(int) $published);
 } else if ($published === '') {
 $query->where('(a.state IN (0, 1))');
 }
 
 3.
 // Filter by category.
 $categoryId = $this->getState('filter.category_id');
 if (is_numeric($categoryId)) {
 $query->where('a.catid = '.(int) $categoryId);
 }
 
 4.
 // Filter by access level.
 if ($access = $this->getState('filter.access')) {
 $query->where('a.access = '.(int) $access);
 }
 
 5.
 // Filter on the language.
 if ($language = $this->getState('filter.language')) {
 $query->where('a.language = ' . $db->quote($language));
 }
 
 return $query;
 
}

Ordering Table Heading


protected function getListQuery()
 {
 // Add the list ordering clause.
 $orderCol = $this->state->get('list.ordering');
 $orderDirn = $this->state->get('list.direction');
 if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
 $orderCol = 'category_title '.$orderDirn.', a.ordering';
 }
 $query->order($db->getEscaped($orderCol.' '.$orderDirn));
 }

 

Load XML Form & Data


Load XML Form

public function getForm($data = array(), $loadData = true)
 {
 // Initialise variables.
 $app = JFactory::getApplication();
 // Get the form.
 $form = $this->loadForm('com_weblinks.weblink', 'weblink', array('control' => 'jform', 'load_data' => $loadData));
 if (empty($form)) {
 return false;
 }
 // Determine correct permissions to check.
 if ($this->getState('weblink.id')) {
 // Existing record. Can only edit in selected categories.
 $form->setFieldAttribute('catid', 'action', 'core.edit');
 } else {
 // New record. Can only create in selected categories.
 $form->setFieldAttribute('catid', 'action', 'core.create');
 }
 // Modify the form based on access controls.
 if (!$this->canEditState((object) $data)) {
 // Disable fields for display.
 $form->setFieldAttribute('ordering', 'disabled', 'true');
 // Disable fields while saving.
 // The controller has already verified this is a record you can edit.
 $form->setFieldAttribute('ordering', 'filter', 'unset');
 }
 return $form;
 }
// Get the form.
1.
$form = $this->loadForm('com_weblinks.weblink', 'weblink', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
 return false;
}
//Determine correct permissions to check.
1.
if ($this->getState('weblink.id')) {
 // Existing record. Can only edit in selected categories.
 $form->setFieldAttribute('catid', 'action', 'core.edit');
} else {
 // New record. Can only create in selected categories.
 $form->setFieldAttribute('catid', 'action', 'core.create');
}
2.
if ($id = (int) $this->getState('article.id')) {
 // Existing record. Can only edit in selected categories.
 $form->setFieldAttribute('catid', 'action', 'core.edit');
 // Existing record. Can only edit own articles in selected categories.
 $form->setFieldAttribute('catid', 'action', 'core.edit.own');
}
else {
 // New record. Can only create in selected categories.
 $form->setFieldAttribute('catid', 'action', 'core.create');
}
//Modify the form based on access controls.
1.
if (!$this->canEditState((object) $data)) {
 // Disable fields for display.
 $form->setFieldAttribute('ordering', 'disabled', 'true');
 $form->setFieldAttribute('state', 'disabled', 'true');
 $form->setFieldAttribute('publish_up', 'disabled', 'true');
 $form->setFieldAttribute('publish_down', 'disabled', 'true');
 // Disable fields while saving.
 // The controller has already verified this is a record you can edit.
 $form->setFieldAttribute('ordering', 'filter', 'unset');
 $form->setFieldAttribute('state', 'filter', 'unset');
 $form->setFieldAttribute('publish_up', 'filter', 'unset');
 $form->setFieldAttribute('publish_down', 'filter', 'unset');
}
2.
if ($this->canEditState((object) $data) != true) {
 // Disable fields for display.
 $form->setFieldAttribute('published', 'disabled', 'true');
 // Disable fields while saving.
 // The controller has already verified this is a record you can edit.
 $form->setFieldAttribute('published', 'filter', 'unset');
}

 

Load Data

protected function loadFormData()
 {
 // Check the session for previously entered form data.
 $data = JFactory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array());
 if (empty($data)) {
 $data = $this->getItem();
 // Prime some default values.
 if ($this->getState('weblink.id') == 0) {
 $app = JFactory::getApplication();
 $data->set('catid', JRequest::getInt('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id')));
 }
 }
 return $data;
 }
// Prime some default values.
 1.
 if ($this->getState('banner.id') == 0) {
 $app = JFactory::getApplication();
 $data->set('catid', JRequest::getInt('catid', $app->getUserState('com_banners.banners.filter.category_id')));
 }
 
 2.
 if ($this->getState('article.id') == 0) {
 $app = JFactory::getApplication();
 $data->set('catid', JRequest::getInt('catid', $app->getUserState('com_content.articles.filter.category_id')));
 }
  
 3.
 if ($this->getState('weblink.id') == 0) {
 $app = JFactory::getApplication();
 $data->set('catid', JRequest::getInt('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id')));
 }
// Check the session for previously entered form data.
 
 1.
 $data = JFactory::getApplication()->getUserState('com_banners.edit.banner.data', array());
 2.
 $data = JFactory::getApplication()->getUserState('com_categories.edit.'.$this->getName().'.data', array());

Controller Form


JControllerForm important function

1.
protected function allowEdit($data = array(), $key = 'id')
{
 // Check if this person is a Super Admin
 if (JAccess::check($data[$key], 'core.admin')) {
 // If I'm not a Super Admin, then disallow the edit.
 if (!JFactory::getUser()->authorise('core.admin')) {
 return false;
 }
 }
 return parent::allowEdit($data, $key);
}
2.
protected function allowSave($data, $key = 'id')
{
 return (JFactory::getUser()->authorise('core.admin', $this->option) && parent::allowSave($data, $key));
}
3.
public function batch($model)
{
 JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
 // Set the model
 $model = $this->getModel('Weblink', '', array());
 // Preset the redirect
 $this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=weblinks'.$this->getRedirectToListAppend(), false));
 return parent::batch($model);
}
4.
protected function allowAdd($data = array())
 {
 // Initialise variables.
 $user = JFactory::getUser();
 $categoryId = JArrayHelper::getValue($data, 'catid', JRequest::getInt('filter_category_id'), 'int');
 $allow = null;
 if ($categoryId) {
 // If the category has been passed in the URL check it.
 $allow = $user->authorise('core.create', $this->option.'.category.'.$categoryId);
 }
 if ($allow === null) {
 // In the absense of better information, revert to the component permissions.
 return parent::allowAdd($data);
 } else {
 return $allow;
 }
 }

Controller Listing


JControllerAdmin important function

1.
public function __construct($config = array())
 {
 parent::__construct($config);
 $this->registerTask('unsetDefault', 'setDefault');
}
2.
function delete(){}
3.
function publish(){}
4.
public function saveorder(){}
5.
public function setDefault(){}
6.
public function duplicate(){}

How to add Category


We can easily add multilevel category in our individual component and  module

1.Add category individual  Componen

1. Add Category option=com_webalive component
Example:
URL: index.php?option=com_categories&view=categories&extension=com_webalive

2.Add category Component Module

1. Add Category com_webalive  "dashbord" module
Example:
URL: index.php?option=com_categories&view=categories&extension=com_webalive.dashboard
Labels:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s