Drupal 7 Views 3 致命错误:无法访问受保护的属性 SelectQuery::$where

发布于 2024-12-15 20:57:39 字数 1061 浏览 2 评论 0原文

当尝试修改 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) 中的过滤器的值有任何想法。

另外,要求回答为什么会访问“受保护的财产”。我是一名编码员。我不想保护任何东西!

提前致谢!

I am getting this error when attempting to modify a value in a Drupal 7 Views 3 filter:

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

Here is the code that is causing this:

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.
  }
}

Probably part of some superhuman object yada yada in D7. Anyone have any ideas on how I can modify the value of a filter in a views 3 view (D7).

And also, request an answer of why access to a "protected property" is happening. I am a coder. I don't want anything protected!

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唯憾梦倾城 2024-12-22 20:57:39

可能有点晚了,但您可以使用 hook_views_query_alter 对其进行修改,这正是出于此目的,如下所示:

function modulename_views_query_alter(&$views,&$query){
    //...rest of the code
    $query->where[0]['conditions'][2]['value'] = $term_no;
}

It might be a bit late but you can modify it using the hook_views_query_alter, which is exactly for that purpose, like this:

function modulename_views_query_alter(&$views,&$query){
    //...rest of the code
    $query->where[0]['conditions'][2]['value'] = $term_no;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文