Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #PostNews_Model.php
- public function find_raw($condition = null)
- {
- $sql = "select news_posts.id, news_posts.title, news_posts.content, news_posts.description, news_posts.thumb, news_posts.created_at, news_posts.category_id, news_category.name from news_posts inner join news_category on news_posts.category_id = news_category.id ";
- if ($condition != null) {
- $sql .= $condition ;
- } else {
- $sql .= ' order by news_posts.id DESC';
- }
- return $this->raw($sql);
- }
- public function countRecord()
- {
- return $this->count($this->table, 'id');
- }
- #News_Controller.php
- public function indexAction()
- {
- $row = $this->model->postNews->countRecord();
- $total_records = $row['total'];
- $current_page = isset($_GET['page']) ? $_GET['page'] : 1;
- $limit = 2;
- $total_page = ceil($total_records / $limit);
- if ($current_page > $total_page){
- $current_page = $total_page;
- }
- else if ($current_page < 1){
- $current_page = 1;
- }
- $start = ($current_page - 1) * $limit;
- $post = $this->model->postNews->find_raw("order by news_posts.created_at DESC limit $start, $limit");
- $data["title"] = "Home page";
- $data["subview"] = "news_home";
- $data["list_post"] = $post;
- $data["list_cate"] = $this->model->cateNews->all();
- $data['current_page'] = $current_page;
- $data['total_page'] = $total_page;
- return $this->view->load('frontend/main', $data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement