Hallo,
schau mal hier ich hatte das selbe Problem wie du ich habe es so gelöst.
PHP-Code:
<?php
//First start with information about the Plugin and yourself. For example:
/**
* @version $Id: nameofplugin.php versionnumber date author
* @copyright Copyright
* @license License, for example GNU/GPL
* All other information you would like to add
*/
//To prevent accessing the document directly, enter this code:
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
//Now define the registerEvent and the language file. Replace 'nameofplugin' with the name of your plugin.
$mainframe->registerEvent( 'onSearch', 'plgSearchNudeln' );
$mainframe->registerEvent( 'onSearchAreas', 'plgSearchNudelnAreas' );
JPlugin::loadLanguage( 'plg_search_nudeln' );
//Then define a function to return an array of search areas. Replace 'nameofplugin' with the name of your plugin.
function &plgSearchNudelnAreas()
{
static $areas = array(
'nudeln' => 'Nudeln'
);
return $areas;
}
//Then the real function has to be created. The database connection should be made.
//The function will be closed with an } at the end of the file.
function plgSearchNudeln( $text, $phrase='', $ordering='', $areas=null )
{
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
//If the array is not correct, return it:
if (is_array( $areas )) {
if (!array_intersect( $areas, array_keys( plgSearchNudelnAreas() ) )) {
return array();
}
}
//It is time to define the parameters! First get the right plugin; 'search' (the group), 'nameofplugin'.
$plugin =& JPluginHelper::getPlugin('search', 'nudeln');
//Then load the parameters of the plugin..
$pluginParams = new JParameter( $plugin->params );
//And define the parameters. For example like this..
$limit = $pluginParams->def( 'search_limit', 50 );
//Use the function trim to delete spaces in front of or at the back of the searching terms
$text = trim( $text );
//Return Array when nothing was filled in
if ($text == '') {
return array();
}
//After this, you have to add the database part. This will be the most difficult part, because this changes per situation.
//In the coding examples later on you will find some of the examples used by Joomla! 1.5 core Search Plugins.
//It will look something like this.
$wheres = array();
switch ($phrase) {
//search exact
case 'exact':
$text = $db->Quote( '%'.$db->getEscaped( $text, true ).'%', false );
$wheres2 = array();
$wheres2[] = 'LOWER(a.nudeln) LIKE '.$text;
$wheres2[] = 'LOWER(a.zutaten) LIKE '.$text;
$where = '(' . implode( ') OR (', $wheres2 ) . ')';
break;
//search all or any
case 'all':
case 'any':
//set default
default:
$words = explode( ' ', $text );
$wheres = array();
foreach ($words as $word)
{
$word = $db->Quote( '%'.$db->getEscaped( $word, true ).'%', false );
$wheres2 = array();
$wheres2[] = 'LOWER(a.nudeln) LIKE '.$word;
$wheres2[] = 'LOWER(a.zutaten) LIKE '.$word;
$wheres[] = implode( ' OR ', $wheres2 );
}
$where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
break;
}
//ordering of the results
switch ( $ordering ) {
//alphabetic, ascending
case 'alpha':
$order = 'a.nudeln ASC';
break;
//oldest first
case 'oldest':
//popular first
case 'popular':
//newest first
case 'newest':
//default setting: alphabetic, ascending
default:
$order = 'a.nudeln ASC';
}
//replace nameofplugin
$searchnudeln = JText::_( 'Nudeln' );
//the database query; differs per situation! It will look something like this:
$query = 'SELECT a.nudeln AS title,a.zutaten as text'
. ' FROM #__nudeln AS a'
. ' WHERE ( '. $where .' )'
. ' AND a.published = 1'
. ' ORDER BY '. $order
;
//Set query
$db->setQuery( $query, 0, $limit );
$rows = $db->loadObjectList();
//The 'output' of the displayed link
foreach($rows as $key => $row) {
$rows[$key]->href = 'index.php?option=com_nudeln&view=nudeln';
}
//Return the search results in an array
return $rows;
}
Du muß aber noch in deiner default.php im Adminbereich von deiner Komponete eine Zeile als titel bezeichnen. z. B. so
PHP-Code:
<th class="title">
<?php echo JHTML::_('grid.sort', 'Nudeln', 'a.nudeln', @$lists['order_Dir'], @$this->lists['order'] ); ?>
</th>
Viel Glück dabei
Lesezeichen