【发布时间】:2014-02-28 20:09:37
【问题描述】:
我对 codeigniter 非常陌生,并尝试编写一个简单的博客应用程序:
控制器:posts.php
class Post extends CI_Model {
function get_posts($num=20, $start=0) {
$this->db->select()->from('posts')->where('active',1)->order_by('date_added','dec')->limit(0,20);
$query = $this->db->get('posts');
return $query->result_array();
}
}
型号:post.php
class Posts extends CI_Controller {
function index() {
$this->load->model('post');
$data['posts'] = $this->post->get_posts();
echo"<pre>";print_r($data['posts']);echo"</pre>";
}
}
我已经在数据库中填充了帖子表。但是,当我尝试获得结果时,我得到了这个:
Array
(
)
mysql> 描述帖子;
+------------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+-------------------+-----------------------------+
| postID | int(10) | NO | PRI | NULL | auto_increment |
| title | varchar(255) | NO | | NULL | |
| post | text | NO | | NULL | |
| date_added | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| userID | int(4) | NO | | NULL | |
| active | tinyint(1) | NO | | NULL | |
| slug | varchar(255) | NO | | NULL | |
+------------+--------------+------+-----+-------------------+------------------
这段代码有什么问题,我该如何解决?
【问题讨论】:
标签: codeigniter-2