所以我为Drupal6.x创建了一个自定义模块,它的工作方式就像我在page.tpl.php页面中看到的那样,但是当我从GUI编辑页面(它允许使用php标记)时,对象是不可访问的。
我可以在会话中设置我可以从GUI和模块访问的值,但这是正确的方法吗?
以下是我得到的错误:
Fatal error: Call to a member function getEmail() on a non-object in /var/www/domain/includes/common.inc(1695) : eval()'d code on line 221
Call Stack
# Time Memory Function Location
1 0.0003 64108 {main}( ) ../index.php:0
2 0.0965 11659504 menu_execute_active_handler( ) ../index.php:18
3 0.1040 12626908 call_user_func_array ( ) ../menu.inc:348
4 0.1040 12627316 node_page_view( ) ../menu.inc:0
5 0.1040 12627532 node_show( ) ../node.module:1797
6 0.1040 12627848 node_view( ) ../node.module:1101
7 0.1040 12628192 node_build_content( ) ../node.module:1006
8 0.1041 12648832 node_prepare( ) ../node.module:1085
9 0.1041 12649112 check_markup( ) ../node.module:1041
10 0.1047 12671980 module_invoke( ) ../filter.module:457
11 0.1047 12693240 call_user_func_array ( ) ../module.inc:462
12 0.1047 12693900 php_filter( ) ../module.inc:0
13 0.1048 12694164 drupal_eval( ) ../php.module:82
14 0.1059 12883728 eval( ''?>
getemail()是自定义模块中类中的函数。我可以从page.tpl.php调用它,这很好,那么为什么我不能从我在管理GUI中编辑的页面调用它呢?
编辑:
从模块添加代码:
//wrapperFunction() is calling the class and setting the values
// this is just a getter/setter class w/ 1 function that formats a phone number, nothing special
$custom = new CustomObj();
$custom->setEmail('blah@blah,com');
return $custom;
页
// calls the wrapper function and returns the object
$custom_obj = wrapperFunction();
echo $custom_obj->getEmail(); // this prints the email just fine
通过管理GUI编辑页面(允许使用PHP标记)
将此代码添加到页面
<?php echo $custom_obj->getEmail(); ?> // throws the error
抱歉,这是我的第一个Drupal模块,所以任何洞察都会很好,因为我也是新使用Drupal的,叹息…