0 レビュー
1 回答
php-Joomlaモジュールで画像を呼び出すことができません
私は最初の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;
}
}
わからない
0
レビュー
答え :
解決策:
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="" />
正直なところ、テンプレートに関連していない画像(この場合は商品画像)は、次の場所に配置する必要があります:
media / mod_mymodule / images /
最終コードで更新:
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; }
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。