我正在使用Drupal Views模块和PHP Views模块。我设置的是5个字段,它们使用PHP块来调用我在Drupal中创建的函数。 PHP代码可以工作并显示我想要的数据。
有“可用变量”可用于可以使用PHP代码的区域,在我的例子中是“输出代码”。例如,你有$ view,$ handler,$ static,$ row等。
我试图访问所有这些,我得到500内部错误或有时我什么也得不到。错误日志指向第122行的“views_php / plugins / views / views_php_handler_field.inc”。我查看了该文件,代码中包含以下行:
$function($this->view, $this, $this->php_static_variable);
我试过调用这样的代码:
<?php
global $view;
print_r($view);
?>
注意我试过没有全局线。
如何在PHP视图中访问这些变量?我正在使用Drupal 6和最新版本的PHP Views模块,即views_php 6.x-1.x-dev。
我用var_dump调用了函数“get_defined_vars()”,有或没有global关键字,我提到的变量都不可用。然而,我可以访问像$ user这样的变量,这些变量在Drupal中是全局的。
答案 0 :(得分:0)
在视图上,您有预览选项。我大部分时间用它来测试我的结果。即使您收到警告框提示您拥有500 internal error
,也请转到设置该视图的页面(路径)。您应该看到$view
变量的输出。请注意,$view
变量显示与列相关的数据。我在寻找的是有关当前位置(行)的信息。您需要使用$static
变量自行设置此代码,它会将数据从一行保留到另一行,以便您可以手动跟踪阵列中的数据位置或数据位置。
我如何使用静态来确定我在当前位置的位置以及下一步需要的位置示例:
if (!$static['isInitial']){
/* Should only enter this condition on the first element.
IsInitial determines this. */
//Count the total amount of issues in Redmine right now.
$static['totalRedmineIssues'] = count($getValue);
$index = 0;
$static['currentIndex'] = $index;
$static['isInitial'] = true;
print_r($static);
} else {
$static['currentIndex'] = $static['currentIndex'] + 1;
$index = $static['currentIndex'];
}