我收到错误“消息:试图获取非对象的属性” 当我尝试从数据库中显示滑块时。
消息:尝试获取非对象的属性 文件名:home / index.php 行号:78
从管理员方面,管理员输入滑块名称,图像和描述 它将显示在主页的用户侧
在localhost(使用wamp)它工作正常,但是当我在线上传时,它会给出错误
Home.php(控制器文件)
if ( ! defined('BASEPATH'))
exit('No direct script access allowed');
class Home extends CI_Controller
{
public function index()
{
$this->load->view('home/index');
}
}
Index.php(查看文件)
<div class="body_resize">
<div class="body">
<div class="border_box">
<div class="box_skitter box_skitter_large">
<?php
$info=$this->dbcommon->getInfo(array('homepage_image'),'homepage',array('status'=>0),'1','','sort_order');
foreach($info as $row)
{
print_r($row);
?>
<ul>
<li>
<img src="<?php echo homepage.'medium/'.$row->homepage_image ?>" class="cubeHide" alt="8_abs.jpg"
width="900" height="400" />
</li>
</ul>
<?php
}?>
</div>
</div>
<script src="js/jquery.skitter.js" type="text/javascript" defer="defer"></script>
<script type="text/javascript" defer="defer">
$(document).ready(function () {
var options = {};
if (document.location.search) {
var array = document.location.search.split('=');
var param = array[0].replace('?', '');
var value = array[1];
if (param == 'animation') {
options.animation = value;
}
else if (param == 'type_navigation') {
if (value == 'dots_preview') {
$('.border_box').css({ 'marginBottom': '40px' });
options['dots'] = true;
options['preview'] = false;
}
else {
options[value] = true;
if (value == 'dots') $('.border_box').css({ 'marginBottom': '40px' });
}
}
}
$('.box_skitter_large').skitter(options);
});
</script>
<div class="body_home">
<h4><strong>Welcome to Softloopers!</strong></h4>
<?php $info=$this->dbcommon->getInfo('','master','','','0,1','');
echo $info->homepage;
?><br />
</div>
getInfo功能
function getInfo($field_name='',$table_name,$array='',$return="",$limit='',$orderby='')
{
if($field_name=='')
{
$sql='select * ';
}
else
{
$str='';
foreach($field_name as $row)
{
$str.=$row.',';
}
$str=rtrim($str,',');
$sql="select ".$str;
}
$sql.= ' from ' .$table_name .' where 2>0 ';
if($array!='')
{
foreach($array as $key=>$value)
{
$sql.="and $key='$value' and";
}
$sql=trim($sql,' and');
}
if($orderby!='')
{
$sql.=" order by $orderby";
}
if($limit!='')
{
$sql.=" limit $limit";
}
$query = $this->db->query($sql);
if($return=='')
{
return $query->row();
}
else
{
return $query->result();
}
}
答案 0 :(得分:0)
如果要将数据传递给控制器进行查看,可以这样做
Home.php(控制器文件)
if ( ! defined('BASEPATH'))
exit('No direct script access allowed');
class Home extends CI_Controller
{
public function index()
{
$data['info']=$this->dbcommon->getInfo(array('homepage_image'),'homepage',array('status'=>0),'1','','sort_order');
$this->load->view('home/index');
}
}
Index.php(查看文件)
<div class="box_skitter box_skitter_large">
<?php
foreach($info as $row)
{
print_r($row);
?>
<ul>
<li>
<img src="<?php echo homepage.'medium/'.$row->homepage_image ?>" class="cubeHide" alt="8_abs.jpg"
width="900" height="400" />
</li>
</ul>
<?php
}?>
</div>