我正在通过在 Joomla 项目上工作来学习和执行 php 如何改进此代码并解决 PHP 通知 - 任何建议 - 解决方案 - 非常感谢!
注意:未定义的变量:cond in*/home/mygames/public_html/components/com_toys/models/category.php 在第 140 行(即 $sql 行)*
function loadSubCat($id,$Carmodel,$minprice,$maxprice){
$mainframe =& JFactory::getApplication();
$option = JRequest::getCmd('option');
$database =& JFactory::getDBO();
global $Itemid;
if($Carmodel!="")
$cond=" and prod_id='$Carmodel' ";
$sql = "Select * from #__toycar_products Where prod_cat_id='".$id."' $cond and prod_status='1' and prod_id in (select v_prod_id from #__toycar_variants) Order By prod_sorder";
注意:尝试在第 200 行的 /home/truecar7/public_html/components/com_toys/models/category.php 中获取非对象的属性
第 200 行是 return $row->id;
function getItemIdByName($Name){
$mainframe =& JFactory::getApplication();
$option = JRequest::getCmd('option');
$database =& JFactory::getDBO();
$sql = "Select id from #__menu Where name = '".$Name."'";
$database->setQuery($sql);
$row = $database->loadObject();
return $row->id;
}
编辑
你好 Lodder & Elin,它可以工作,但就像这样,否则它会在返回 $row 行上显示未定义的变量通知。
function getItemIdByName($Name){
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')
->from('#__menu')
->where('id = ' . $db->quote($Name));
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row){
$row = $row->msg;
}
$row='';
return $row;
}