[英]Joomla multiple functions in single model/view
I'm trying to create a drop down list that populates a <select>
with options pulled from a DISTINCT
argument. 我正在尝试创建一个下拉列表,该列表填充从DISTINCT
参数提取的选项的<select>
。 Code looks like this: 代码如下:
function cityData() {
$db =& JFactory::getDBO();
$query = "SELECT DISTINCT MSTCITY FROM " . $db->nameQuote('#__mls') . " ORDER BY MSTCITY;";
$db->setQuery($query);
$tbl = $db->loadObjectList();
echo $tbl;
}
Now, I have two views: one is RAW for an AJAX call and the other is the default view. 现在,我有两个视图:一个是RAW以进行AJAX调用,另一个是默认视图。 I figured the simplest way would be to just use the default view and do it in PHP, since the default view wasn't really being used for much anyway. 我认为最简单的方法是只使用默认视图并在PHP中进行操作,因为无论如何,默认视图并没有真正被使用。 So I added a function: 所以我增加了一个功能:
function dropList($tpl = null){
$model = &$this->getModel();
$array = $model->cityData();
$this->assignRef('array', $array );
parent::display($tpl);
}
And then a call in the page 然后在页面中拨打电话
<?php
$thing = $this->array;
echo $thing;
?>
Nothing is being displayed for the echo $thing;
对于echo $thing;
什么都没有显示echo $thing;
. 。 In the past, when I used PHP to build content instead of AJAX, this worked fine. 过去,当我使用PHP而不是AJAX来构建内容时,这种方法很好用。 I don't know if it's using loadObjectList()
that's not giving me anything or what. 我不知道是否正在使用loadObjectList()
并没有给我任何东西。 I know the mySQL query works, as it's be tested in the cmd and I get the result I expect. 我知道mySQL查询有效,因为已经在cmd中对其进行了测试,并且得到了预期的结果。
In order to debug and see the array values you need to use print_r. 为了调试并查看数组值,您需要使用print_r。 In your case edit the default.php file to 在您的情况下,将default.php文件编辑为
<?php
$thing = $this->array;
print_r($thing);
?>
You can also use var_dump 您也可以使用var_dump
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.