Hi Jonathan,
Do you need the dropdown in the frontend or backend?
I have done it like this, but another way might be better for your components
- create a fork folder
- create a helperfile in your fork folder
- in the view.html.php, create a filter with the list from that helper
- in the layout (i.e. default.php) echo that filter.
More detailed (will post some code later):
Create fork folder
Create a "fork" folder in your admin part (or the site part)
Lets assume you have a view named "someview".
Create in the fork folder the following folder: views/someview
Copy the view.html.php and index.html from _fork/views/someview into your fork/views/someview.
Copy the displayDefault() function from the original into it.
Create in your fork/views/someview a folder tmpl
Copy default.php and index.html (can be different in your component) from _fork/views/someview/tmpl into your fork/views/someview/tmpl.
The index.html file are just empty pages.
Create helper file
Create a folder in your fork: fork/helpers and a file name functions.php, also copy a index.html (empty page)
Create filter in (forked) view.html.php
Create a list in put it in the default filters array. Put the code in the display()
$filters['sites']->jdomOptions = array(
'dataValue' => $state->get('filter.site_name'),
'labelKey' => 'site_name',
'list' => MyComponentFunctions::getSites()
);
Echo the filter in your layout
Put the following code where you want the dropdown.
<?php echo $this->filters['sites']->input;?>
code for helper file
This is example code
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
if( !class_exists('MyComponentFunctions') ){
/**
* JoomBMSFunctions Class
*/
class MyComponentFunctions{
/**
* @var string $_name is name of group;
*
* @access private;
*/
private static $_name = 'MyComponent Functions';
/**
* getter of name variable
*/
public static function getName(){
return self::$_name;
}
public static function getSites() {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select(array('id', 'site_name'))
->from('#__yourothercomponent_sitetable')
->where('published = 1'); //if you have this
$db->setQuery($query);
$result = $db->loadObjectList();
return $result;
}
}
}
?>
I can give more help if you need it.
I can even create the code for you, but you would have to create some designmockups so that I can see where and how you want the data.