尝试修改Drupal 7 Views 3过滤器中的值时出现此错误:
Fatal error: Cannot access protected property SelectQuery::$where in /Users/joe/Sites/sdgea/docroot/sites/all/modules/custom/sdge_video/sdge_video.module on line 275
以下是导致此问题的代码:
function modulename_views_pre_execute(&$view) {
if (is_numeric($term_no)) {
// set the filter
$view->filter['tid']->value[$term_no] = $term_no;
// set the query
$view->query->where[0]['conditions'][2]['value'] = $term_no;
// set the build info
$view->build_info['query']->where->conditions[0]['field']->conditions[0]['field']->conditions[2]['value'] = $term_no;
//$view->build_info['query']->where->conditions[0]['field']->conditions[0]['field']->conditions[2]['value'] = $term_no; // <-- This line specifically is causing fatality.
}
}
可能是D7中一些超人物yada yada的一部分。任何人都对如何在视图3视图(D7)中修改过滤器的值有任何想法。
此外,请求回答为什么要访问“受保护财产”。我是一名程序员。我不想要任何保护!
提前致谢!
答案 0 :(得分:2)
可能有点迟了但您可以使用 hook_views_query_alter 对其进行修改,这正是出于此目的,如下所示:
function modulename_views_query_alter(&$views,&$query){
//...rest of the code
$query->where[0]['conditions'][2]['value'] = $term_no;
}