简体   繁体   中英

Joomla : how to publish a PHP / HTML file to a Module Position

I am looking for a solution to publish a PHP / HTML file to a Joomla Module position. This is not a Module but is a part of additional features of my template. Hence I don't want to convert it into a Module.

My php File is something like this:

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

 ?> 

What this script does is........ It converts the output of this file and saves it in a Static HTML format. Now I want to publish this HTML file to a given module position. How can I do so?

Kindly help.

try using this module: http://www.joomlaos.de/Joomla_CMS_Downloads/Joomla_Plugins/includePHP.html

after installing simply:

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

in your module, or exlude your code in an external php file and do something like

{phpfile} /home/mysite/public_html/mycode.php {/phpfile}

The easiest way would be to create a module, since you have no database connection just copy any of existing modules change the names of the files and in the XML file place the code in the main file and you are ready.

Example:

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 -->

That is all you need, after that just place all your files in the modules directory and assign the module through Joomla to appropriate position. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM