ITeye博客

joomla中添加按单元分类搜索

aiou · 2009-04-27 09:13 · joomla · 编程语言 · HTML · PHP · SQL · Markdown

Views/search/ view.html.php中: Display函数中添加修改 [code="php"] $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') );[/code] 和 [code="php"]$this->assign('cat', $state->get('cat'));[/code] Views/search/tmpl/ default_form.php 添加修改 [code="php"] : lists['cat'];?> [/code] Models/search.php中: __construct()函数中添加修改 [code="php"]$cat = JRequest::getInt('cat', '1'); $this->setSearch($keyword, $match, $ordering,$cat);[/code] setSearch函数中添加修改 [code="php"]function setSearch($keyword, $match = 'all', $ordering = 'newest', $cat = '1')[/code] 和 [code="php"] if(isset($cat)) { $this->setState('cat', $cat); }[/code] getData函数中添加修改: [code="php"] $results = $dispatcher->trigger( 'onSearch', array( $this->getState('keyword'), $this->getState('match'), $this->getState('ordering'), $areas['active'], $this->getState('cat')) );//顺序要对[/code] /controller.php中 Search函数添加修改 [code="php"]$post['cat'] = JRequest::getInt('cat', null, 'post');[/code] pluginSearchContent.php中 添加修改 [code="php"]function plgSearchContent( $text, $phrase='', $ordering='', $areas=NULL,$cat='' )[/code] 和 [code="php"] if($cat!=null&&$cat!=''){ $cat_filter = ' AND a.catid in ( '.$cat.')'; } else{ $cat_filter = ''; }[/code] 在sql语句中WHERE后添加.$filt条件。 完成! 小技巧:var_dump(变量名)可以打印变量信息,不仅仅是值。 上面是分类的修改方法,单元的方法同上

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。