User Login    
 + Register
  • Main navigation
Login
Username:

Password:

Remember me



Lost Password?

Register now!
Who's Online
89 user(s) are online (9 user(s) are browsing XoopsWiki)

Members: 3
Guests: 86

kontrolfreek, GPboarder, hursic, more...
[Main Page]

Dev:making a simple module:using echo

From XOOPS Project

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

Printable version | Disclaimers | Privacy policy
Category: Development

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");
         o $myArray = array("Tribal Tech", "Face First", "Tuna Laguna", "Try it!", "Hoven Droven", "Swedish folk music done cool");
   * include XOOPS_ROOT_PATH."/header.php";
* echo "";
   * for ($i=0;$i<count($myArray);$i++)
   * {
* echo "";
   * $i++;
* echo "";
   * }
* echo "
My Module Table
".$myArray[$i]."->".$myArray[$i]."
";
   * 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:

   * <? //functions.php
   * function getTable()
   * {
   * $myArray = array("Richard Nixon", "American Hero", "George W. Bush", "Vegetable", "Hoven Droven", "Swedish Folk Music done cool");
* $str = "";
   * for ($i=0;$i<count($myArray);$i++)
   * {
* $str .= "";
   * $i++;
* $str .= "";
   * }
* $str .= "
My Module Table
".$myArray$i?."->".$myArray$i?."
";
   * 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.2 using a simple template

1.2.3 an active template

back to dev:Tutorials

Retrieved from "http://www.xoops.org/modules/mediawiki/index.php/Dev:making_a_simple_module:using_echo"

This page has been accessed 635 times. This page was last modified 17:25, 15 December 2007. Content is available under XOOPS Project.


Developers for Hire
Local Support Sites
Make a donation
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


Powered by
XOOPS Code hosted on SourceForge

Powered by PHP



Powered by MySQL

Powered by Smarty

OSI certified

All content on this site is subject to the Creative Commons License
Advertisement