本人是初学者,想请教下一个问题啊,希望知道的帮忙解惑啊!
我再model中用get方法去查询所需数据表中的内容,具体如下:
function get_books($num,$offset)
{
$query = $this ->db ->get('christian_books',$num,$offset);
return $query;
}
然后我再controller中调用这个方法。具体如下:
function index()
{
$this ->load ->library('pagination');
$config['base_url'] = site_url('books/index');
$config['total_rows'] = $this ->db ->count_all('christian_books');
$config['per_page'] = 5;
$config['uri_segment'] = 3;
$config['full_tag_open'] = "<p>";
$config['full_tag_close'] = "</p>";
$this ->pagination ->initialize($config);
$this ->load ->model('books_model');
$data['results'] = $this ->books_model ->get_books($config['per_page'],$this ->uri ->segment(3)); //var_dump($data);
$this ->load ->library('table');
$this ->table ->set_heading('ID','title','Author','Description');
$this ->load ->view('books_view',$data);
}
我遇到的问题是:这里的$data['results'],这里为什么必须用这个变量,如果不用就会报出一下错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: results
Filename: views/books_view.php
Line Number: 10
这里的results变量不是根据自己所需而定的吗?求解惑啊!!!
|