Joomla TMPL default.php文件中的SELECT语句

时间:2011-06-16 23:15:24

标签: joomla joomla1.5

我正在开发一个Joomla组件。我有几年,几个月和旅行日期。

想法是

2011 2012 2013 2014(链接),让我们说2011年是活跃的。下面我有

2011年9月

9月的音乐会;    9月的音乐会#2;    9月的音乐会#3;

oct,2011

音乐会在oct#1;    音乐会在oct#2;    音乐会在oct#3;

nov,2011

新闻#1中的音乐会;    nov#2中的音乐会;    nov#3中的音乐会;

我想你可以理解显示结构。

我有一张桌子,在我定制的页面上,我会毫无问题地处理它。但是我在Joomla上开发它,所以我有点困惑。

我有一个显示年份的函数getYEAR,在Tmpl default.php我有foreach。

现在我创建了另一个显示月份的函数getMonth,它看起来像这样:

                $now = date('Y'); 
        $year = JRequest::getInt('year',  $now);
        $db =& JFactory::getDBO();
        $query = "SELECT DISTINCT MONTH( date ), #__concert_month.monthname 
                FROM #__concert_info
                JOIN #__concert_month ON #__concert_month.id = MONTH( date ) 
                WHERE YEAR( date ) = {$year} AND date >= CURDATE( ) 
                ORDER BY MONTH( date )";
        $db->setQuery( $query );
        $this->_month = $db->loadObjectList();

        return $this->_month;

没关系。但问题是我想根据月份选择游览场所,就像我上面描述的月份 - >音乐会,月 - >音乐会

通常我会这样做

    SElECT smth1
    foreach1 (smth1 as smt1)

    echo Monthname  $id=smth1

    SELECT smth2 WHERE MONTH( date ) = $id
    foreach2(smth2 as smt2)
    endforeach2


    endforeach1

如何在tmpl-> default.php中的FOREACH中进行SELECT?或者还有其他解决方案吗?

1 个答案:

答案 0 :(得分:0)

事实证明,您可以将SELECT直接放入tmpl->default.php文件中。我想我昨天错了,今天它有效。

我仍然不喜欢将SELECT放入default.php的想法(我更喜欢将它放在模型中,应该如此)。