注意:第37行default.php中未定义的偏移量:2注意:未找到第37行default.php中非对象的属性
你好,我是joomla的新手,创建模块mod_推荐。我已经将数据放入注意:第37行default.php中未定义的偏移量:2注意:未找到第37行default.php中非对象的属性,php,joomla,joomla2.5,Php,Joomla,Joomla2.5,你好,我是joomla的新手,创建模块mod_推荐。我已经将数据放入$rows=$db->loadObjectList()中从帮助文件 echo后面的$rows中的数据是 Array ( [0] => stdClass Object ( [name] => james [testimonial] => Ipsum is simply dummy text of the printing and typese
$rows=$db->loadObjectList()中代码>从帮助文件
echo后面的$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>
.到目前为止一切正常,但如果我取消发布或取消后端数据的特征,将引发类似这样的错误
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_estimational.php
中
$data = helperClassname :: getRecord($param);
在您的default.php
上有如下内容
if(sizeof($data) > 0){
foreach($data as $key=>$value){
echo "<br/>Name".$value->name;
}
}
if(sizeof($data)>0){
foreach($key=>$value形式的数据){
回显“
名称”。$value->Name;
}
}
有关模块结构和调用的更多信息,请查看此
希望对您有所帮助。检查数组是否有值,然后仅访问其索引值是的,谢谢,但是如何在循环中获取该数组,使其获得连续性并显示可用的数据。我已经尝试了for each循环,但没有更改,完全空白,请帮助我解决。可能重复的
if(sizeof($data) > 0){
foreach($data as $key=>$value){
echo "<br/>Name".$value->name;
}
}