Get XOOPS XOOPSXOOPS FAQFAQ ForumsForums NewsNews ThemesThemes ModulesModules

Search

Donate to XOOPS!

Please select an amount to donate


Do you want your username revealed with your donation?
Yes - List me as a Generous Donor
No - List my donation as from an Anonymous Donor


Local Support

Advertisement

XOOPS Code hosted on SourceForge

Cumulus Tag Cloud

admin Arabic banner block Christmas comments cumulus DayDawn dhsoft e-Commerce E-Learning Git Google GUI hacks instant-zero jQuery module mygalleries news Nordic Olédrion oxygen PageRank PHP rmcommon security SEO simple-XOOPS Smarty sport tag Theme tutorial wiki WOX xoops XoopsEngine ZendFramework

New Users

Registering user

# 133963

hillsync

Welcome to XOOPS!
[Main Page]

Making a simple module: Using echo

(Redirected from Using echo)

Main Page | Recent changes | Edit this page | Page history | Switch to MediaWiki mode

Printable version | Disclaimers | Privacy policy
Category: DevWiki

DevWiki Index | DevWiki Tutorials

This method may be OK if your module is a simple project with only a few pages in it. The main drawback is that it breaks with the Xoops rules, so whatever you do now may not work in the next version of Xoops. Don't use this if you plan a public release of your module! It's only mentioned here to be used in your own small custom-made projects.

The biggest pro of the method is that you don't have to update anything while coding, you just save your code, press F5 and you see the results onscreen.

To print stuff onscreen using this method you only need to edit your index.php file.

<?php
require_once("../../mainfile.php");
$myArray = array("Tribal Tech", "Face First", "Tuna Laguna", "Try it!", "Hoven Droven", "Swedish folk music done cool");
include XOOPS_ROOT_PATH."/header.php";
echo "<table><tr><td colspan='2' align='center'>My Module Table</td></tr>";

for ($i=0;$i<count($myArray);$i++)
{
	echo "<tr><td align='right'>".$myArray[$i]."-></td>";
	$i++;
	echo "<td>".$myArray[$i]."</td></tr>";
}

echo "</table>";
include XOOPS_ROOT_PATH."/footer.php";
?>

Quick and dirty. You could get away with a single echo call by assembling a string with .= and using echo to output things at the bottom. Refactoring:

The index.php file may get large and messy as our module grows. It may be a good idea to clean things up by creating a folder "includes" with a file "functions.php" inside it:

<?php //functions.php

function getTable()
{
	$myArray = array("Richard Nixon", "American Hero", "George W. Bush", "Vegetable", "Hoven Droven", "Swedish Folk Music done cool");
	$str = "<table><tr><td colspan='2' align='center'>My Module Table</td></tr>";
	
	for ($i=0;$i<count($myArray);$i++)
	{
		$str .= "<tr><td align='right'>".$myArray$i?."-></td>";
		$i++;
		$str .= "<td>".$myArray$i?."</td></tr>";
	}
	
	$str .= "</table>";
	return $str;
}
?>

This way we can get away with a smaller index.php file, and it'll be easier to see what we're talking about.

<?php //index.php
require_once("../../mainfile.php");
include XOOPS_ROOT_PATH."/include/functions.php";

// this line must be defined BEFORE header.php
$xoopsOption['template_main'] = "earplane_main.html";
include XOOPS_ROOT_PATH."/header.php";
echo getTable();
include XOOPS_ROOT_PATH."/footer.php";
?>

Now let's continue with outputting the string to a simple template instead of using the echo statement... Other parts:


1.2.1 Using echo

1.2.2 Using a simple template

1.2.3 An active template


Back to DevWiki Tutorials

Retrieved from "http://xoops.org/modules/mediawiki/index.php/Making_a_simple_module:_Using_echo"

This page has been accessed 5,225 times. This page was last modified 13:53, 21 July 2009. Content is available under XOOPS Web Application System.