自定义组件:在视图对象中检索过滤器

时间:2013-10-17 21:20:53

标签: joomla joomla2.5 joomla-component

在我的自定义组件中......

  • 我显示国家/地区列表作为链接和名为“狗”的额外链接
  • 点击一个国家/地区后,通过在模型中添加过滤器country,可以显示该国家/地区的人员列表(查看:人员)。
  • 如果点击“狗”,则会显示拥有狗的人员列表(查看:人员),无论他们居住在哪个国家/地区。这可以通过在模型中添加过滤器dog来完成。

任务
在人物视图中,我想根据国家或狗是否设置为过滤器来显示标题,例如“奥地利”或“有狗的人”。

我尝试了什么......
从我的view-object读取活动过滤器会将两个过滤器返回为1,即使它未设置:

["filter.country"]=>int(1)
["filter.dog"]=>int(1)
["list.limit"]=>string(2) "20"
(...)

我的模型文件(摘录):

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);
}

编辑:

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');
    (...) 

我迷路了 - 从状态中读取信息是否无意义,或者我的过滤器设置不正确?

0 个答案:

没有答案