在非对象4上调用成员函数result_array()

时间:2017-02-16 11:39:01

标签: php codeigniter

我在打开我的网络时遇到麻烦,并且说在非对象上调用成员函数result_array()并且我无法弄清楚如何解决它。我希望你们中的任何人都可以帮助我。

所以这是我的网络控制器

 <?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);

    }



}

这是我的produk_populer.php

    <div class="allcontain">
    <div class="feturedsection">
    <h1 class="text-center"><span class="bdots">&bullet;</span>P R O D U K<span class="carstxt">P O P U L E R</span>&bullet;</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>

这也是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();

}



}

这就是我需要问的一切,我希望有人可以帮助我。感谢

2 个答案:

答案 0 :(得分:0)

$this->mymodel->GetProduk()->result_array();

$this->mymodel无效。你没有加载模型。您必须在使用$this->load->model('mymodel')调用之前加载mymodel。或者您也可以使用autoload.php

从全局加载它

答案 1 :(得分:0)

假设您已加载数据库类,以下工作正常。

<?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;

}



}