joomla中添加按单元分类搜索

Views/search/ view.html.php中:
Display函数中添加修改
		$cat = array();
		$cat[] = JHTML::_('select.option',  '16', JText::_( 'cat1' ) );
		$cat[] = JHTML::_('select.option',  '2', JText::_( 'cat2' ) );
		$cat[] = JHTML::_('select.option',  '3', JText::_( 'cat3' ) );
		$cat[] = JHTML::_('select.option',  '4', JText::_( 'cat4' ) );
		$cat[] = JHTML::_('select.option',  '5', JText::_( 'cat5' ) );
		$lists['cat'] = JHTML::_('select.genericlist',   $cat, 'cat', 'class="inputbox"', 'value', 'text', $state->get('cat') );


$this->assign('cat',		$state->get('cat'));


Views/search/tmpl/ default_form.php
添加修改
		<tr>
			<td colspan="3">
				<label for="cat">
					<?php echo JText::_( '选择分类' );?>:
				</label>
				<?php echo $this->lists['cat'];?>
			</td>
		</tr>


Models/search.php中:
__construct()函数中添加修改
$cat		= JRequest::getInt('cat', '1');
		$this->setSearch($keyword, $match, $ordering,$cat);

setSearch函数中添加修改
function setSearch($keyword, $match = 'all', $ordering = 'newest', $cat = '1')


		if(isset($cat)) {
			$this->setState('cat', $cat);
		}

getData函数中添加修改:
			$results = $dispatcher->trigger( 'onSearch', array(
			$this->getState('keyword'),
			$this->getState('match'),
			$this->getState('ordering'),
			$areas['active'],
			$this->getState('cat')) );//顺序要对


/controller.php中
Search函数添加修改
$post['cat']	=  JRequest::getInt('cat', null, 'post');


pluginSearchContent.php中
添加修改
function plgSearchContent( $text, $phrase='', $ordering='', $areas=NULL,$cat='' )


	if($cat!=null&&$cat!=''){
		$cat_filter = ' AND a.catid in ( '.$cat.')';
	}
	else{
		$cat_filter = '';
	}

在sql语句中WHERE后添加.$filt条件。
完成!
小技巧:var_dump(变量名)可以打印变量信息,不仅仅是值。

上面是分类的修改方法,单元的方法同上

你可能感兴趣的:(html,sql,PHP)