目前我有组件模块,我想从另一个表中添加一些数据。
这是我当前的 helper.php 代码:
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
class Modprop_lastHelper
{
function getItems($ShowFeatured,$OrderBy,$Order,$amountShow,$ShowPropertyID)
{
switch($OrderBy) {
case 0 :
$OrderBy = 'p.id';
break;
case 1 :
$OrderBy = 'p.name';
break;
case 2 :
$OrderBy = 'p.price';
break;
case 3 :
$OrderBy = 'p.hits';
break;
case 4 :
$OrderBy = 'p.refresh_time';
break;
}
switch($Order) {
case 0 :
$Order = 'ASC';
break;
case 1 :
$Order = 'DESC';
break;
}
if($ShowPropertyID){$where= 'WHERE p.id IN ('.$ShowPropertyID.')';}else{$where= 'WHERE p.published = 1 ';}
if($ShowFeatured){$sqlFeatured= ' AND p.featured = 1';}
$db = &JFactory::getDBO();
$query = 'SELECT p.*, i.name as imagename,c.name as name_category,t.name as name_type,cy.name as name_country,s.name as name_state,l.name as name_locality,'
. ' CASE WHEN CHAR_LENGTH(p.alias) THEN CONCAT_WS(":", p.id, p.alias) ELSE p.id END as Pslug,'
. ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as Cslug,'
. ' CASE WHEN CHAR_LENGTH(cy.alias) THEN CONCAT_WS(":", cy.id, cy.alias) ELSE cy.id END as CYslug,'
. ' CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(":", s.id, s.alias) ELSE s.id END as Sslug,'
. ' CASE WHEN CHAR_LENGTH(l.alias) THEN CONCAT_WS(":", l.id, l.alias) ELSE l.id END as Lslug, '
. ' CASE WHEN CHAR_LENGTH(t.alias) THEN CONCAT_WS(":", t.id, t.alias) ELSE t.id END as Tslug '
. ' FROM #__properties_products AS p '
. ' LEFT JOIN #__properties_country AS cy ON cy.id = p.cyid '
. ' LEFT JOIN #__properties_state AS s ON s.id = p.sid '
. ' LEFT JOIN #__properties_locality AS l ON l.id = p.lid '
. ' LEFT JOIN #__properties_category AS c ON c.id = p.cid '
. ' LEFT JOIN #__properties_type AS t ON t.id = p.type '
. ' LEFT JOIN #__properties_images AS i ON i.parent = p.id '
. $where
. $sqlFeatured
. ' GROUP BY p.id '
. ' ORDER BY '.$OrderBy.' '.$Order
. ' LIMIT '.$amountShow;
$db->setQuery($query);
$items = $db->loadObjectList();
// $items = ($items = $db->loadObjectList())?$items:array();
//echo str_replace('#_','jos',$query);
return $items;
}
function NameCategory()
{
$db =& JFactory::getDBO();
$query = 'SELECT * FROM #__properties_category WHERE published = 1 ORDER BY id';
$db->setQuery($query);
$Categories = $db->loadObjectList();
foreach ($Categories as $row) :
$Category[$row->id] = $row->name;
endforeach;
return $Category;
}
function NameType()
{
$db =& JFactory::getDBO();
$query = 'SELECT * FROM #__properties_type WHERE published = 1 ORDER BY name';
$db->setQuery($query);
$Types = $db->loadObjectList();
foreach ($Types as $row) :
$Type[$row->id] = $row->name;
endforeach;
return $Type;
}
function NameLocality()
{
$db =& JFactory::getDBO();
$query = 'SELECT * FROM #__properties_locality WHERE published = 1 ORDER BY name';
$db->setQuery($query);
$Localities = $db->loadObjectList();
foreach ($Localities as $row) :
$Locality[$row->id] = $row->name;
endforeach;
return $Locality;
}
function getItemid( $TableName )
{
$db =& JFactory::getDBO();
$query = 'SELECT id FROM #__menu' .
' WHERE LOWER( link ) = "index.php? option=com_properties&view='.$TableName.'&id=0"';
$db->setQuery( $query );
$output = $db->loadResult();
if(!$output){
$query = 'SELECT id FROM #__menu' .
' WHERE LOWER( link ) = "index.php? option=com_properties&view=properties"';
$db->setQuery( $query );
$output = $db->loadResult();
}
if(!$output){
$query = 'SELECT id FROM #__menu' .
' WHERE LOWER( link ) = "index.php?option=com_properties&view=properties&cid=0&tid=0"';
$db->setQuery( $query );
$output = $db->loadResult();
}
return $output;
}
}
?>
我在 helper.php 中添加了额外的函数来从另一个表 properties_users 中获取数据:
function Units()
{
$db =& JFactory::getDBO();
$query = ' SELECT u.* '
. ' FROM #__properties_units as u '
. ' WHERE u.published = 1 AND u.productid = p.id'
. ' order by u.ordering ';
$db->setQuery($query);
$Units = $db->loadObjectList();
return $Units;
}
当我尝试从 Units 表中显示某些内容时,什么也没有出现。我在我的 tmp 视图中使用以下代码:
<?php echo $Units->title;?>
代码有什么问题?