In my custom component...
- I display a list of countries as links and an extra-link called "dogs"
- once a country is clicked, a list of persons in that country is displayed (view: persons), by adding a filter
country
in the model. - if "dogs" is clicked, a list of persons owning a dog is displayed (view: persons), regardless of the country they live in. This is done by adding a filter
dog
in the model.
Task
in persons-view, I want to display a title depending if country or dog is set as filter, e.g. "Austria" or "Persons with Dogs".
What I tried...
reading the active filter from my view-object returns both filters always as 1
, even if it isn't set:
["filter.country"]=>int(1)
["filter.dog"]=>int(1)
["list.limit"]=>string(2) "20"
(...)
my model-file (snippet):
protected function populateState($ordering = null, $direction = null) {
$app = JFactory::getApplication();
$country = $this->getUserStateFromRequest($this->context.'.filter.country', 'country', '', null, false);
$this->setState('filter.country', (int) $country);
$dog = $this->getUserStateFromRequest($this->context.'.filter.dog', 'dog', '', null, false);
$this->setState('filter.dog', (int) $dog);
(...)
parent::populateState($ordering, $direction);
}
EDIT:
public function __construct($config = array()) {
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'country',
'dog'
);
}
parent::__construct($config);
}
view.html.php:
public function display($tpl = null) {
$app = JFactory::getApplication();
$this->state = $this->get('State');
(...)
I'm lost - is it nonsense to read the information from the state, or are my filters set incorrectly?