升级Joomla后,PHP代码无法正常工作

时间:2013-11-05 15:54:20

标签: php joomla

我正在使用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'));

helper.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

2 个答案:

答案 0 :(得分:0)

joomla框架中有一些更改,如果要在后面的Joomla版本中使用它们,则需要在J1.5扩展中进行少量更改。

Joomla Wiki中描述了很多这些内容。但是我假设问题出在代码的其他部分,可能在处理表单数据的文件中。

答案 1 :(得分: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();

希望这有帮助