0

I am creating a simple module in joomla. I have a file 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'));

The last line is what of interest here. I want to take the variable $percentValues and pass it on for use in the module's default.php template.

In my default.php all I have is:

<?php echo $percentValues; ?> 

This does not work. The error I get tells me the variable is undefined.

However, if I do:

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

It works just fine. Can someone explain why I can't use the variable?There must be something big I am missing. Using Joomla! 3.1.

Thank you in advance.

Jared

4

1 回答 1

2

重新排列代码

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' ) );

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

于 2013-08-08T05:42:16.383 回答