我想从我的模型中传递值来查看,但是错误
以下错误消息
遇到严重错误
的PHP错误消息:在非对象上调用成员函数result()
文件名:views / baju.php
行号:13
回溯:
这是我的模特
<?php
class Baju extends CI_Model{
function __construct(){
parent::__construct();
}
function tampil_semua_baju(){
$query = $this->db->get('baju');
return $query->result();
}
}
这是我的控制器
<?php
class Baju_C extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->helper('url');
}
public function tampil_data(){
$this->load->model('Baju','all_item');
$data['item_baju'] = $this->all_item->tampil_semua_baju();
$this->load->view('baju',$data);
}
}
这是我的观点
<html>
<head>
<title>Little Monster</title>
<meta charset="utf-8">
<meta name="viewport" content="wodth=device-width, initial-scale=1">
<link href="<?php echo base_url('asset/bootstrap/dist/css/bootstrap.css') ?>" rel="stylesheet">
<link href="<?php echo base_url('asset/bootstrap/dist/css/bootstrap.min.css') ?>" rel="stylesheet">
<script src="<?php echo base_url('asset/bootstrap/dist/js/bootstrap.js') ?>"></script>
<script src="<?php echo base_url('asset/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
</head>
<body>
<?php
foreach($item_baju->result() as $hasil):
?>
<p><?php echo $hasil->nama; ?></p>
<?php endforeach; ?>
</body>
</html>
答案 0 :(得分:2)
像这样更新你的观点:
<html>
<head>
<title>Little Monster</title>
<meta charset="utf-8">
<meta name="viewport" content="wodth=device-width, initial-scale=1">
<link href="<?php echo base_url('asset/bootstrap/dist/css/bootstrap.css') ?>" rel="stylesheet">
<link href="<?php echo base_url('asset/bootstrap/dist/css/bootstrap.min.css') ?>" rel="stylesheet">
<script src="<?php echo base_url('asset/bootstrap/dist/js/bootstrap.js') ?>"></script>
<script src="<?php echo base_url('asset/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
</head>
<body>
<?php
foreach($item_baju as $hasil):
?>
<p><?php echo $hasil->nama; ?></p>
<?php endforeach; ?>
</body>
</html>