ตัวยอย่าง code กรณีตัวอย่าง ไฟล์ views mdocmans/tmpl/default.php
code ส่วนสำหรับการค้นหา
โค้ด: เลือกทั้งหมด
<select name="filter_category1" onchange="this.form.submit()">
<option value=""> - เลือกหมวดหมู่ - </option>
<?php echo JHtml::_('select.options', $this->Category1, 'value1', 'text1', $this->state->get('filter.category1'), true);?>
</select>
ส่วนการแสดงผล
โค้ด: เลือกทั้งหมด
<?php
foreach ($this->items as $i => $item) {
$canEditOwn = $canDo->get('core.edit.own')? $this->helper->AccessOwn($item->id, 'rrisk_docman', 'user_id_create') : false ;
?>
<tr class="row<?php echo $i % 2; ?>">
<td align="center"><?php echo $i + 1;?></td>
<td align="center">
<?php echo JHtml::_('grid.id', $i, $item->rd_id); ?> </td>
<td>
<?php
if($canEditOwn) {
?>
<a href="<?php echo $url;?>">
<?php echo $item->rd_name;?> </a>
<?php
} else {
echo $item->name;
}
?> </td>
<td><?php echo $item->description;?></td>
<td><?php echo $helper->convertToTimeThai($item->date_create);?></td>
</tr>
<?php
}
?>
โค้ด: เลือกทั้งหมด
<?php
/*
Component License
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import the Joomla modellist library
jimport('joomla.application.component.modellist');
class RriskModelMdocmans extends JModelList {
function getCategory1() {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('dc_id AS value1 ,category AS text1')->from('#__rrisk_docman_category');
$db->setQuery($query);
$db->query();
return $db->loadObjectList();
}
protected function populateState($ordering = null, $direction = null) {
// Load the filter state.
$category1 = $this->getUserStateFromRequest($this->context.'.filter.category1', 'filter_category1');
$this->setState('filter.category1', $category1);
// List state information.
parent::populateState('d.dc_id', 'asc');
}
protected function getListQuery() {
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select('d.rd_id,
d.dc_id,
d.rd_name,
d.description,
d.size,
d.md5_mame,
u.name')->from('#__rrisk_docman AS d');
$query->join('LEFT','#__users AS u ON u.id = d.user_id_create');
if ($this->getState('filter.category1') != '') {
$query->where('d.dc_id ='.$db->quote($this->getState('filter.category1')));
}
$query->order($db->escape($this->getState('list.ordering', 'd.rd_id')).' '.$db->escape($this->getState('list.direction', 'ASC')));
return $query;
}
}
?>
ค้นหา
โค้ด: เลือกทั้งหมด
function display($tpl = null) {
โค้ด: เลือกทั้งหมด
$this->Category1 = $this->get('Category1');