dongxing6802 2010-10-15 19:26
浏览 62
已采纳

无法从GUI PHP标记访问Drupal自定义模块对象

So I have created a custom module for Drupal 6.x and it works as I can see the desired results in the page.tpl.php page, but when I edit a page from the GUI (it allows php tags) the object is not accessible.

I can set the values in a SESSION which I can access from the GUI as well as the module but is this the correct way to do this?

Here is the error I get:

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() is a function in a class that is in my custom module. I can call it from the page.tpl.php just fine, so why can't I call it from a page that I have edited in the Admin GUI?

EDIT:

Adding Code from Module:

//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;

page.tpl.php

// calls the wrapper function and returns the object
$custom_obj = wrapperFunction();
echo $custom_obj->getEmail(); // this prints the email just fine

Edit page through the Admin GUI (Allows PHP tags) Adding this code to the page

<?php echo $custom_obj->getEmail(); ?> // throws the error

Sorry this is my first Drupal Module so any insight would be great as I'm also new to using Drupal, sigh...

  • 写回答

2条回答 默认 最新

  • duanfu7840 2010-10-18 17:38
    关注

    Well to solve my problem I moved all the logic to the module and the fields I wanted to change on the fly I set to session. so in the page.tpl.php page I checked if the SESSION value was set, if it was use it else use a default value. By using SESSION I was able to pass all the desired values to any page regardless of where the page was made (GUI or Hard coded).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?