【问题标题】:Passing a parameter in a Joomla! module在 Joomla! 中传递参数!模块
【发布时间】:2013-08-08 03:51:51
【问题描述】:

我正在 joomla 中创建一个简单的模块。我有一个文件 mod_progress.php。

defined( '_JEXEC' ) or die( 'Restricted access' );
// Include the syndicate functions only once
require_once( dirname(__FILE__).'/helper.php' );
require( JModuleHelper::getLayoutPath( 'mod_progress' ) );

$document = JFactory::getDocument();
$document->addStyleSheet(JURI::base() . 'modules/mod_progress/tmpl/styles.css');

$percentValues = htmlspecialchars($params->get('percentValues'));

最后一行是这里感兴趣的内容。我想获取变量 $percentValues 并将其传递给模块的 default.php 模板。

在我的 default.php 中,我只有:

<?php echo $percentValues; ?> 

这不起作用。我得到的错误告诉我变量未定义。

但是,如果我这样做:

<?php $percentValues = htmlspecialchars($params->get('percentValues'));
 echo $percentValues; ?>

它工作得很好。有人可以解释为什么我不能使用这个变量吗?我一定有什么大不了的。使用 Joomla! 3.1.

提前谢谢你。

贾里德

【问题讨论】:

    标签: php joomla joomla3.0


    【解决方案1】:

    重新排列你的代码

    defined( '_JEXEC' ) or die( 'Restricted access' );
    // Include the syndicate functions only once
    require_once( dirname(__FILE__).'/helper.php' );
    
    $percentValues = htmlspecialchars($params->get('percentValues'));
    
    $document = JFactory::getDocument();
    $document->addStyleSheet(JURI::base() . 'modules/mod_progress/tmpl/styles.css');
    
    require( JModuleHelper::getLayoutPath( 'mod_progress' ) );
    

    应该在包含布局之前声明变量。

    【讨论】:

    • 谢谢。你知道它为什么关心订单吗?只是好奇。
    猜你喜欢
    • 2017-12-01
    • 1970-01-01
    • 2020-03-18
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多