Advertisement
Guest User

controler

a guest
Oct 25th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Home extends CI_Controller {
  4. private $tpl;
  5.  
  6. public function __construct(){
  7. parent::__construct();
  8. $this->load->model('addcats');
  9. }
  10. public function index(){
  11. $cats = $this->addcats->get();
  12. $tpl['cats'] = $cats;
  13. $tpl['content'] = 'home/index';
  14. $this->load->view('template', $tpl);
  15. }
  16.  
  17. private function loadView($content) {
  18. $this->tpl['content'] = $content;
  19. $this->load->view('template', $this->tpl);
  20. }
  21.  
  22. public function add(){
  23. $tpl['content'] = 'home/addcat';
  24. $this->load->view('template', $tpl);
  25. }
  26.  
  27. public function cats($parent_id = 0){
  28. $this->db->where('parent_id', $parent_id);
  29. $data = $this->db->get('cats')->result_array();
  30. if(empty($data)){
  31. return;
  32. }
  33. echo '<ul>';
  34. foreach ($data as $key => $value) {
  35. echo '<li>'.$value['name'];
  36. $this->cats($value['id']);
  37. echo '</li>';
  38. }
  39. echo '</ul>';
  40. }
  41.  
  42.  
  43. public function create(){
  44. $post = $this->input->post();
  45. $this->addcats->parent_id = $post['parent_id'];
  46. $this->addcats->name = $post['name'];
  47. $this->addcats->sort = $post['sort'];
  48. $this->addcats->level = $post['level'];
  49.  
  50. $this->addcats->create();
  51. $_SESSION['alert'] = 'თქვენი პოსტი წარმატებით დაემატა!';
  52. redirect('home/index');
  53.  
  54. }
  55.  
  56. public function delete($cat_id){
  57. $cats = $this->addcats->getUserById($cat_id);
  58. if(!$cats){
  59. redirect('home/index');
  60. }
  61. $cats->delete();
  62. redirect('home/index');
  63. }
  64.  
  65. public function edit($cat_id) {
  66. $cats = $this->addcats->getUserById($cat_id);
  67. if(!$cats){
  68. redirect('home/index');
  69. }
  70. $tpl['cat_id'] = $cat_id;
  71. $tpl['addcats'] = $cats;
  72. $tpl['content'] = 'home/edit';
  73. $this->load->view('template', $tpl);
  74. }
  75. public function update($cat_id){
  76. $cat = $this->addcats->getUserById($cat_id);
  77. if(!$cat){
  78. redirect('home/index');
  79. }
  80. $post = $this->input->post();
  81. $cat->parent_id = $post['parent_id'];
  82. $cat->name = $post['name'];
  83. $cat->sort = $post['sort'];
  84. $cat->level = $post['level'];
  85. $cat->update();
  86. redirect('home/index');
  87. }
  88.  
  89. }
  90.  
  91. /* End of file home.php */
  92. /* Location: ./application/controllers/home.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement