无法在Joomla模块中调用图像

时间:2016-04-20 12:35:06

标签: php joomla module

我正在研究我的第一个joomla模块,并坚持调用图像。 一切似乎都有效,我能够安装模块并在正确的位置使用它,但是当我使用时,图像丢失了。  下面是我在helper.php中使用的代码

    <?php
/**
 * Helper class for Hello World! module
 * 
 * @package    Joomla.Tutorials
 * @subpackage Modules
 * @link http://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module
 * @license        GNU/GPL, see LICENSE.php
 * mod_helloworld is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 */
class modpdisplayHelper
{
    /**
     * Retrieves the hello message
     *
     * @param   array  $params An object containing the module parameters
     *
     * @access public
     */    
    public static function getpdisplay($params)
    {
        return <<<HTML
    <div class="product-image-wrapper">
                                <div class="single-products">
                                        <div class="productinfo text-center">
                                            <img src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/images/home/product1.jpg" alt="" />
                                            <h2>FREE</h2>
                                            <p>Easy Polo Black Edition</p>
                                            <a href="#" class="btn btn-default add-to-cart"><i class="fa fa-book"></i>Details</a>
                                        </div>
                                        <div class="product-overlay">
                                            <div class="overlay-content">
                                                <p>Product Details goes Here</p>
                                                <h2>FREE</h2>
                                                <p>Easy Polo Black Edition</p>
                                                <a href="#" class="btn btn-default add-to-cart"><i class="fa fa-book"></i>Details</a>
                                            </div>
                                        </div>
                                </div>
</div>
HTML;
    }
}

1 个答案:

答案 0 :(得分:1)

您无法在Joomla模块中使用$this->baseurl$this->template。这些只能在模板文件中使用。

相反,请使用:

<?php
  $app  = JFactory::getApplication();
  $path = JUri::base(true) . '/templates/' . $app->getTemplate();
?>

<img src="<?php echo path; ?>/images/home/product1.jpg" alt="" />

说实话,与您的案例产品图片相关的不是的图片应放在:

  

媒体/ mod_mymodule /图像/

使用最终代码进行更新:

public static function getpdisplay($params)
{
    $app  = JFactory::getApplication();
    $path = JUri::base(true) . '/templates/' . $app->getTemplate();

    $html = '<div class="product-image-wrapper">
                <div class="single-products">
                        <div class="productinfo text-center">
                            <img src="' . $path . '/images/home/product1.jpg" alt="" />
                            <h2>FREE</h2>
                            <p>Easy Polo Black Edition</p>
                            <a href="#" class="btn btn-default add-to-cart"><i class="fa fa-book"></i>Details</a>
                        </div>
                        <div class="product-overlay">
                            <div class="overlay-content">
                                <p>Product Details goes Here</p>
                                <h2>FREE</h2>
                                <p>Easy Polo Black Edition</p>
                                <a href="#" class="btn btn-default add-to-cart"><i class="fa fa-book"></i>Details</a>
                            </div>
                        </div>
                </div>
            </div>';

    return $html;
}