Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #PostNews_Model.php
  2. public function find_raw($condition = null)
  3. {
  4. $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 ";
  5.  
  6. if ($condition != null) {
  7. $sql .= $condition ;
  8. } else {
  9. $sql .= ' order by news_posts.id DESC';
  10. }
  11. return $this->raw($sql);
  12. }
  13.  
  14. public function countRecord()
  15. {
  16. return $this->count($this->table, 'id');
  17. }
  18.  
  19.  
  20. #News_Controller.php
  21. public function indexAction()
  22. {
  23. $row = $this->model->postNews->countRecord();
  24. $total_records = $row['total'];
  25. $current_page = isset($_GET['page']) ? $_GET['page'] : 1;
  26. $limit = 2;
  27. $total_page = ceil($total_records / $limit);
  28. if ($current_page > $total_page){
  29. $current_page = $total_page;
  30. }
  31. else if ($current_page < 1){
  32. $current_page = 1;
  33. }
  34. $start = ($current_page - 1) * $limit;
  35.  
  36. $post = $this->model->postNews->find_raw("order by news_posts.created_at DESC limit $start, $limit");
  37. $data["title"] = "Home page";
  38. $data["subview"] = "news_home";
  39. $data["list_post"] = $post;
  40. $data["list_cate"] = $this->model->cateNews->all();
  41. $data['current_page'] = $current_page;
  42. $data['total_page'] = $total_page;
  43. return $this->view->load('frontend/main', $data);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement