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条)

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起