3

我正在构建一个 joomla 2.5 模块,我想从模块参数访问数据传递,但我收到以下错误:致命错误:调用非对象上的成员函数 get() 我的代码如下:

助手.php

class modFeedGrabber
{
    function feedurl( $params ){
        return $params->get('feedUrl');
    }
}

mod_feedGrabber.php

defined( '_JEXEC' ) or die( 'Restricted access' );
$sitebase = JPATH_BASE;
$doc =& JFactory::getDocument();

// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'/helper.php' );
$feed = new modFeedGrabber();
$url = $feed->feedurl();
require( JModuleHelper::getLayoutPath( 'mod_feedGrabber' ) );

mod_feedGrabber.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" client="site" method="install">
    <name>Scroll Feed</name>
    <author>Josiah Gerald</author>
    <version>1.0.0</version>
    <date>03-04-2013</date>
    <description>A simple feed scroller.</description>
    <files>
        <filename>mod_feedGrabber.xml</filename>
        <filename module="mod_feedGrabber">mod_feedGrabber.php</filename>
        <filename>index.html</filename>
        <filename>helper.php</filename>
        <filename>tmpl/default.php</filename>
        <filename>tmpl/index.html</filename>
        <folder>tmpl</folder>
    </files>
    <config>
        <fields name="params">
            <fieldset name="basic">
                <field
                    name="feedUrl"
                    type="url"
                    size="50"
                    label="Feed URL"
                    description="Enter the url of the feed" />


 </fieldset>
       </fields>
 </config>
</extension>  

默认的.php

    <?php 
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
<div id='feed' class="<?php echo $module_sfx; ?>"><?php echo $url; ?>
</div>
4

1 回答 1

1

我可以看到提供的代码的主要问题是您没有将 传递$params给您的辅助函数。它应该是这样的:

defined( '_JEXEC' ) or die( 'Restricted access' );
$sitebase = JPATH_BASE;
$doc =& JFactory::getDocument();

// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'/helper.php' );
$feed = new modFeedGrabber();
$url = $feed->feedurl($params);
require( JModuleHelper::getLayoutPath( 'mod_feedGrabber' ) );

此外,您的 XML 无效,因为它缺少fieldset和标签的结束fields标签。它应该如下所示:

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" client="site" method="install">
    <name>Scroll Feed</name>
    <author>Josiah Gerald</author>
    <version>1.0.0</version>
    <date>03-04-2013</date>
    <description>A simple feed scroller.</description>
    <files>
        <filename>mod_feedGrabber.xml</filename>
        <filename module="mod_feedGrabber">mod_feedGrabber.php</filename>
        <filename>index.html</filename>
        <filename>helper.php</filename>
        <filename>tmpl/default.php</filename>
        <filename>tmpl/index.html</filename>
        <folder>tmpl</folder>
    </files>
    <config>
        <fields name="params">
            <fieldset name="basic">
                <field
                    name="feedUrl"
                    type="url"
                    size="50"
                    label="Feed URL"
                    description="Enter the url of the feed"
                />
            </fieldset>
        </fields>
    </config>
</extension>

作为提示,您可以通过将 XML 文件拖到浏览器窗口中来快速检查它是否有效,例如,您在上面发布的代码会导致:

Chrome 中的损坏的 XML 错误

于 2013-04-12T00:28:25.903 回答