[英]PHP Notice: Trying to get property of non-object in /wp-includes/query.php on line 4654
[英]Notice: Undefined offset: 2 in default.php on line 37 Notice: Trying to get property of non-object in default.php on line 37 File not found
您好,iam是joomla的创建模块mod_testimonial的新手。 我已经将数据放入$rows = $db->loadObjectList();
从帮助文件中
和回声后$ rows中的数据是
Array
(
[0] => stdClass Object
(
[name] => james
[testimonial] => Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
[regdate] => 2013-12-31 13:24:29
[id] => 37
)
[1] => stdClass Object
(
[name] => Tom
[testimonial] => Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
[regdate] => 2013-12-31 14:45:56
[id] => 38
)
[2] => stdClass Object
(
[name] => Alyson
[testimonial] => is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s
[regdate] => 2014-01-03 14:52:09
[id] => 42
)
)
在我的default.php文件中,我已经像这样从数组中获取了数据。
<p><?php print_r($rows[0]->testimonial);?><span class="testimonial-by"> —<?php print_r($rows[0]->name);?>,<?php echo date('M Y',strtotime($rows[1]->regdate)); ?>,</span></p>
<p><?php print_r($rows[1]->testimonial);?><span class="testimonial-by">—<?php print_r($rows[1]->name);?>,<?php echo date('M Y',strtotime($rows[2]->regdate)); ?>,</span></p>
<p><?php print_r($rows[2]->testimonial);?><span class="testimonial-by">—<?php print_r($rows[2]->name);?>,<?php echo date('M Y',strtotime($rows[0]->regdate)); ?>,</span></p>
我的助手文件是
static function getRecord($params)
{
$db = JFactory::getDBO();
$query = "SELECT name,testimonial,regdate,id FROM #__testimonial WHERE published = '1' AND featured='1' ";
$db->setQuery( $query);
$rows = $db->loadObjectList();
return $rows;
}
。直到这里一切正常,但是如果我将后端的数据取消发布或取消功能,将引发如下错误
Notice: Undefined offset: 2 in modules\mod_testimonial\tmpl\default.php on line 37
Notice: Trying to get property of non-object in modules\mod_testimonial\tmpl\default.php on line 37
File not found
我知道这是因为没有
offset [2] => stdClass Object
(
[name] => Alyson
[testimonial] => is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s
[regdate] => 2014-01-03 14:52:09
[id] => 42
)
我想给出一个适当的循环,以便跳过此问题,并且我不需要更改模板。
请帮助我,非常沮丧地尝试了所有的东西。 谢谢
尝试这个,
在您的帮助文件中。
function getRecord($params)
{
$db = JFactory::getDBO();
$query = "SELECT name,testimonial,regdate,id FROM #__testimonial WHERE published = '1' AND featured='1' ";
$db->setQuery( $query);
return $db->loadObjectList();
}
在您的模块文件mod_testimonial.php
有类似
$data = helperClassname :: getRecord($param);
在您的default.php
有类似的内容。
if(sizeof($data) > 0){
foreach($data as $key=>$value){
echo "<br/>Name".$value->name;
}
}
有关模块结构和调用的更多信息,请查看此样本横幅幻灯片演示模块
希望能有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.