0

我正在开发一个 joomla 网站。一些开发人员创建了一个显示城市选择数据的模块。该代码在 joomla 1.5 上运行良好,但在升级 joomla 后,它显示所有数据而不过滤。我正在研究解决方案。我没有编码。这是代码,php 5.3 有什么不推荐使用的吗?

 // no direct access
defined('_JEXEC') or die('Restricted access'); 

if(isset($_SESSION['CITY_SELECTION'])){
    $selected_city = $_SESSION['CITY_SELECTION'];
}
else {
    $selected_city = '-SELECT A CITY-';
}

echo "<div id='city_selector'><form name='CITY_SELECTION_FORM' method='get' action='/residential-home.html'>" ;
echo "<SELECT id='city_input' name='CITY_SELECTION' onchange='this.form.submit();'>"; 


echo $selected_city;

foreach ($cities as $city=>$cityname) 
{
    $select = "";   
    if(strtolower(trim($selected_city))==strtolower(trim($cityname)))
    {
         $select = " SELECTED";
    }
    else
    {
        $select = "";
    }
    echo "<OPTION value='".$cityname."'".$select."> ".$cityname."</option>"; 
}

echo '</select>';
echo '</form></div>';  

mod_cityselection.php

// no direct access
defined('_JEXEC') or die('Restricted access');

// Include the syndicate functions only once
require_once (dirname(__FILE__).DS.'helper.php');

$cities = CitySelection::getCities();

require(JModuleHelper::getLayoutPath('mod_cityselection'));

助手.php

defined('_JEXEC') or die('Direct Access to this location is not allowed.');

class CitySelection
{
    /**
     * Returns a list of cities
    */
    public function getCities()
    {
        // get a reference to the database
        $db = &JFactory::getDBO();

        // get the list of cities in the custom city_selection
        $query = 'SELECT CS.cityname FROM #__city_selection AS CS Order By cityname ASC;';

        $db->setQuery($query);
        $cities = $db->loadResultArray();

        return $cities;
    } //end getCities

} //end CitySelection
4

2 回答 2

0

尝试在使用 Joomla 2.5 编码标准的helper.php文件中使用以下查询:

$db = JFactory::getDbo();     
$query = $db->getQuery(true);

$query->select($db->quoteName('CS.cityname'))
 ->from($db->quoteName('#__city_selection', 'CS'))
 ->order($db->quoteName('cityname') . ' DESC');

$db->setQuery($query);

$cities = $db->loadObjectList();

希望这可以帮助

于 2013-11-05T17:32:33.850 回答
0

joomla 框架中有几处更改,如果您想在以后的 Joomla 版本中使用它们,则需要对 J1.5 扩展进行小的更改。

其中很多都在Joomla Wiki中进行了描述。但是我认为问题出在代码的其他部分,可能在处理表单数据的文件中。

于 2013-11-05T16:34:40.620 回答