---
title: "joomla中添加按单元分类搜索"
author: "aiou"
date: "2009-04-27T09:13:40Z"
tags: ["HTML", "PHP", "SQL"]
categories: ["编程语言"]
slug: "joomla"
draft: false
lastmod: "2009-04-27T09:13:40Z"
id: 375314
url: "https://aiou.iteye.com/blog/375314"
---

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-&gt;get('cat') );\[/code] 和 \[code="php"]$this-&gt;assign('cat', $state-&gt;get('cat'));\[/code] Views/search/tmpl/ default\_form.php 添加修改 \[code="php"] : lists\['cat'];?&gt; \[/code] Models/search.php中： \_\_construct()函数中添加修改 \[code="php"]$cat = JRequest::getInt('cat', '1'); $this-&gt;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-&gt;setState('cat', $cat); }\[/code] getData函数中添加修改： \[code="php"] $results = $dispatcher-&gt;trigger( 'onSearch', array( $this-&gt;getState('keyword'), $this-&gt;getState('match'), $this-&gt;getState('ordering'), $areas\['active'], $this-&gt;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(变量名)可以打印变量信息，不仅仅是值。 上面是分类的修改方法，单元的方法同上