简体   繁体   中英

joomla 2.5 module: how to foreach loop put in tmpl/default.php

in joomla module to get data from database we use the code

public static function getdb($params)
{
// Get a database object
$db = JFactory::getDbo();

$query = $db->getQuery(true);
$query->select('*');
$query->from('#__categories');

// sets up a database query for later execution
$db->setQuery($query);

// fetch result as an object list
$result = $db->loadObjectList();
foreach ( $result as $row ) {
echo "$row->extension .<br>";
}
}

my question is how to use this foreach loop in tmpl/default.php ? and then wat will be my helper.php code?

foreach ( $result as $row ) {
echo "$row->extension .<br>";
}

if i use this foreach loop into default.php then it will better for me. pls someone help

helper.php

public static function getdb($params) {

    $db = JFactory::getDbo();

    $query = $db->getQuery(true);
    $query->select('*');
    $query->from('#__categories');

    $db->setQuery($query);
    $result = $db->loadObjectList();

    return $result;
}

default.php:

//call the function from the helper.php
$result = modHelloWorldHelper::getdb($params);

//display the results
foreach ( $result as $row ) {
    echo $row->extension . "<br>";
}

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