Reputation: 35
i have trouble when open my web and its said Call to a member function result_array() on a non-object and i cant figure out how to solve it. i hope any of you guys can help me out.
so this is my web controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Web extends CI_Controller {
public function index(){
$data = array(
"produk_populers" => $this->mymodel->GetProduk()->result_array()
);
$comp = array(
"header" => $this->load->view("header",array(),true),
"navbar" => $this->load->view("navbar",array(),true),
"iklan" => $this->load->view("iklan",array(),true),
"produk_populer" => $this->load->view("produk_populer",$data,true),
"kategori" => $this->load->view("kategori",array(),true),
"footer" => $this->load->view("footer",array(),true),
);
$this->load->view("index",$comp);
}
public function html_produk_populer(){
$data = array(
"produk_populer" => $this->mymodel->GetProduk()
);
return $this->load->view("produk_populer",$data,true);
}
}
and this is my produk_populer.php
<div class="allcontain">
<div class="feturedsection">
<h1 class="text-center"><span class="bdots">•</span>P R O D U K<span class="carstxt">P O P U L E R</span>•</h1>
</div>
<div class="feturedimage">
<div class="row firstrow">
<div class="col-lg-6 costumcol colborder1">
<div class="row costumrow">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 img1colon">
<img src="<?php echo base_url()."assets/"; ?>images/<?php echo $produk_populer['gambar_produk']; ?>" alt="floridina">
</div>
<?php foreach ($produk_populers as $produk_populer) { ?>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 txt1colon">
<div class="featurecontant">
<h1><?php echo $produk_populer['nama_produk']; ?></h1>
<p><?php echo $produk_populer['info_produk']; ?></p>
<h1><?php echo $produk_populer['harga_produk']; ?></h1>
<!--<<button id="btnRM" onClick="rmtxt()">READ MORE</button>
<div id="readmore">
<h1></h1>
<p><br>
sed do eiusmod tempor incididunt <br>"Lorem ipsum dolor sit amet, consectetur ,<br>
sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1 ,
sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1
sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1<br>
</p>
<button id="btnRL">READ LESS</button>
</div>-->
</div>
</div>
<?php } ?>
</div>
</div>
<!--<div class="col-lg-6 costumcol colborder2">
<div class="row costumrow">
<?php //foreach ($produk_populers as $produk_populer) { ?>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 img2colon">
<img src="<?php //echo base_url()."assets/"; ?>images/<?php //echo $produk_populer['gambar_produk']; ?>" alt="floridina">
</div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 txt1colon ">
<div class="featurecontant">
<h1><?php //echo $produk_populer['nama_produk']; ?></h1>
<p><?php //echo $produk_populer['info_produk']; ?></p>
<h1><?php //echo $produk_populer['harga_produk']; ?></h1>
<div id="readmore">
<h1></h1>
<p><br>
sed do eiusmod tempor incididunt <br>"Lorem ipsum dolor sit amet, consectetur ,<br>
sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1 ,
sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1
sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1<br>
</p>
<button id="btnRL">READ LESS</button>
</div>
</div>
</div>
<?php } ?>
</div> -->
</div>
</div>
</div>
also this is mymodel.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Mymodel extends CI_Model {
public function GetProduk($where=""){
$data = $this->db->query('select * from produk');
return $data -> result_array();
}
}
so that is all i need to ask, i hope theres anyone who can help me. Thanks
Upvotes: 1
Views: 2391
Reputation: 1485
Following should work assuming you have loaded DB class.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Mymodel extends CI_Model {
public function GetProduk($where=""){
$data = $this->db->query('select * from produk');
return $data;
}
}
Upvotes: 1
Reputation: 21
$this->mymodel->GetProduk()->result_array();
$this->mymodel
is not working. You didn't load model. You have to load mymodel before call it by using $this->load->model('mymodel')
. Or also you can load it from globally by using autoload.php
Upvotes: 0