简体   繁体   English

Drupal 6视图2:PHP代码段

[英]Drupal 6 Views 2: PHP Snippets

I am using Views 2 to get information from my Drupal 6 site. 我正在使用Views 2从我的Drupal 6网站获取信息。 After getting the data, I want to use a little PHP to do some calculations that are unavailable through Views + Views calc. 获取数据后,我想使用一些PHP来执行一些无法通过Views + Views calc获得的计算。 What is the best way to go about doing this? 这样做的最佳方法是什么?

I could alter the "Header" or "Footer" text, set the input format to "PHP Code", and try to access the $view object? 我可以更改“页眉”或“页脚”文本,将输入格式设置为“ PHP代码”,然后尝试访问$ view对象?

This didn't work for me: 这对我不起作用:

<?php

global $view;
print_r($view);

?>

Any other ideas of what to do? 关于该怎么办的其他想法? What if I wanted to make an entire module that drew off existing Views instead of pulling info out of the db itself? 如果我想制作一个可以提取现有Views的完整模块,而不是将信息从数据库本身中提取出来,该怎么办?

There is a whole API for views , you may find that for your needs you can use a custom template and do the maths in that. 有用于视图的完整API ,您可能会发现,可以根据需要使用自定义模板并进行数学计算。 If you are only using the calculations for output then this should be ok, even from a purists point of view. 如果仅将计算用于输出,那么即使从纯粹主义者的角度来看,也应该可以。

If you need to do more than a little display logic, I think hook_views_pre_render() is the right hook for you. 如果您需要做更多的显示逻辑,我认为hook_views_pre_render()是您的正确选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM