Joomla:如何将PHP / HTML文件发布到模块位置

时间:2010-12-22 09:58:09

标签: php joomla

我正在寻找将PHP / HTML文件发布到Joomla模块位置的解决方案。这不是模块,但是我的模板的其他功能的一部分。因此,我不想将其转换为模块。

我的php文件是这样的:

<?php

       <--Some functions here -->

ob_start();

        <-- Some php code here -->

$contents = ob_get_clean();

$fp = fopen('hallo.html', 'w') or die('couldn\'t open file for writing.');
fwrite($fp, $contents);
fclose($fp); 

 ?> 

此脚本的作用是........它会转换此文件的输出并将其保存为静态HTML 格式。现在我想将此HTML文件发布到给定的模块位置。我怎么能这样做?

请帮助。

2 个答案:

答案 0 :(得分:2)

尝试使用此模块: http://www.joomlaos.de/Joomla_CMS_Downloads/Joomla_Plugins/includePHP.html

安装后简单:

{php} echo 'this is code'; {/php}

在您的模块中,或者将您的代码排除在外部php文件中并执行类似

的操作
{phpfile} /home/mysite/public_html/mycode.php {/phpfile}

答案 1 :(得分:1)

最简单的方法是创建一个模块,因为你没有数据库连接只需复制任何现有模块就可以更改文件的名称,而在XML文件中将代码放在主文件中就可以了。

示例:

mod_static / mod_static.php

<?php

// no direct access
defined('_JEXEC') or die('Restricted access');    

// Include the syndicate functions only once
require_once(dirname(__FILE__).DS.'helper.php');

// Initialize the helper class
$helper = new modStaticHelper($params);

// Your PHP code here, any functions and data manipulations


require(JModuleHelper::getLayoutPath('mod_static'));

<强> mod_static / mod_static.xml

<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.5.0">
    <name>mod_static</name>
    <author>mod_static</author>
    <creationDate>December 2010</creationDate>
    <copyright></copyright>
    <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
    <authorEmail></authorEmail>
    <authorUrl></authorUrl>
    <version>0.5b</version>
    <description></description>
    <files>
        <filename module="mod_static">mod_static.php</filename>
    </files>
    <params>            
    </params>
</install>

<强> mod_static / TMPL /如default.php

<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>

<!-- Your HTML code and the ready PHP variables to echo here -->

这就是您所需要的,然后将所有文件放在modules目录中,并通过Joomla将模块分配到适当的位置。祝你好运!