根据文档,我正在后端列表页面创建一个过滤器http://docs.joomla.org/J2.5:How_to_add_custom_filters_to_components
但是我遇到了错误 在非对象上调用成员函数 get()用代码
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
//Following variables used more than once
$this->sortColumn = $this->state->get('list.ordering');
$this->sortDirection = $this->state->get('list.direction');
$this->searchterms = $this->state->get('filter.search');
在文件视图/zzz/视图中.html.php
代码如何工作?谢谢。
调用喜欢
$this->get('State');
将调用名为
public function getState()
在Corrensponding模型中,除非它以其他方式实例化,否则它将models/zzz.php
以下三行尝试加载函数 populateState() 在模型列表中保存的值(zzz
模型从中继承),以检索模型中设置的排序和筛选器。 但显然$this->state
没有设置(上行),所以先测试getState()
的输出。
为避免此错误,您可以查看是否设置了状态:
if (isset($this->state)) {
$this->sortColumn = $this->state->get('list.ordering');
etc...
但是你应该真正尝试通过调试代码来理解为什么它不是设置的。