简体   繁体   中英

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. 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. 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. 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; . In the past, when I used PHP to build content instead of AJAX, this worked fine. I don't know if it's using loadObjectList() that's not giving me anything or what. I know the mySQL query works, as it's be tested in the cmd and I get the result I expect.

In order to debug and see the array values you need to use print_r. In your case edit the default.php file to

<?php 
$thing = $this->array;
print_r($thing);
?>

You can also use var_dump

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