简体   繁体   English

joomla 2.5模块:如何将foreach循环放入tmpl / default.php

[英]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 在joomla模块中以从数据库获取数据,我们使用以下代码

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 ? 我的问题是如何在tmpl / default.php中使用此foreach循环? and then wat will be my helper.php code? 然后wat将是我的helper.php代码?

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

if i use this foreach loop into default.php then it will better for me. 如果我使用此foreach循环到default.php,那么对我会更好。 pls someone help 请某人帮助

helper.php 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: default.php:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Joomla 2.5在default.php中加载javaScript文件 - Joomla 2.5 Loading javaScript Files inside default.php Joomla。 如何在default.php中编辑菜单的链接? - Joomla. How to edit the link of the Menu in default.php? 如何将$ _GET [&#39;&#39;]值从mod_modulenamet / mpl / default.php中的$ document-&gt; addStylesheet()转换为joomla模块的css.php文件 - How to $_GET [' '] value from $document->addStylesheet() in mod_modulenamet/mpl/default.php to css.php file of joomla module 如何通过Ajax将default.php中的值传递给view.html.php-joomla3.x - How to pass a value from default.php to view.html.php through ajax - joomla3.x 如何在Joomla 3 default.php文件中更改菜单类以模仿自定义菜单类 - How to change the menu classes in Joomla 3 default.php file to mimic custom menu classes 在joomla组件中的default.php内部查看路径 - View path inside default.php in joomla component 从default.php隐藏的传递变量不起作用-joomla 3 - passing variable as hidden from default.php is not working - joomla 3 在Virtuemar选项卡/ default.php / Joomla 3.7.5中插入Chronoforms - Insert Chronoforms in Virtuemar tabs / default.php / Joomla 3.7.5 解析错误:语法错误,在第84行的/home/future/public_html/modules/mod_mainmenu/tmpl/default.php中出现意外的&lt;&lt; - Parse error: syntax error, unexpected '<' in /home/future/public_html/modules/mod_mainmenu/tmpl/default.php on line 84 PHP foreach覆盖结果Joomla 2.5 - PHP foreach overwriting results Joomla 2.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM