普通网友 2014-05-14 09:37
浏览 30

我获取数据数组时出现Codeigniter错误

I have a model which passes one record to my controller but I keep receiving these two errors

Message: Missing argument 1 for Quotes_model::get_records(), called in /home/digibite/public_html/development/quote/application/controllers/welcome.php on line 12 and defined

Message: Missing argument 2 for Quotes_model::get_records(), called in /home/digibite/public_html/development/quote/application/controllers/welcome.php on line 12 and defined

I have been playing around with this for almost an hour and can't get my head around it.

My model

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Quotes_model extends CI_Model{

  function __construct(){
     parent::__construct();
  }

  function get_records($limit, $offset){
    $query = $this->db->select('*')
             ->from('quotes')
             ->join('authors', 'authors.id = quotes.author_id')
             ->join('genre', 'genre.id = quotes.id')
             ->order_by('id', 'RANDOM')
             ->limit($limit, $offset);
    $data = array();
    $data[] = array (

      'title' => $row->title,
      'slug' => $row->slug,
      'meta_keys' => $row->meta_keys,
      'meta_description' => $row->meta_description,
      'content' => $row->content,
      'views' => $row->views,  
    );

    return $data;


  }
} 

And this is my controller

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {


    public function index()
    {


        $this->load->helper('url');
        $this->load->model('quotes_model');
        $data['quote']= $this->quotes_model->get_records();
        $this->load->view('welcome_message');

    }
}
  • 写回答

1条回答 默认 最新

  • doujuan2688 2014-05-14 09:40
    关注

    This error is because, you are not passing any arguments through the function in controller.

    $data['quote']= $this->quotes_model->get_records();
                                                     ^
    

    and you are trying to call the arguments ( you are supposed to pass to the model ) in the query.

    $query = $this->db->select('*')
                 ->from('quotes')
                 ->join('authors', 'authors.id = quotes.author_id')
                 ->join('genre', 'genre.id = quotes.id')
                 ->order_by('id', 'RANDOM')
                 ->limit($limit, $offset);
                         ^         ^
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退