Producttitle.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Producttitle extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->_model('Model_producttitle','producttitle');
  6. }
  7. //定义方法的调用规则 获取URI第二段值
  8. public function _remap($arg,$arg_array)
  9. {
  10. if($arg == 'add')//添加
  11. {
  12. $this->_add();
  13. }
  14. else if($arg == 'edit')//修改
  15. {
  16. $this->_edit($arg_array);
  17. }
  18. else if($arg == 'del')//修改
  19. {
  20. $this->_del();
  21. }
  22. else
  23. {
  24. $this->_index();
  25. }
  26. }
  27. //管理
  28. public function _index()
  29. {
  30. $post = $this->input->post(NULL, TRUE);
  31. if(isset($post['page']))
  32. {
  33. $page = $this->input->post('page',true);
  34. $perpage = $this->input->post('perpage',true);
  35. $title = $this->input->post('title',true);
  36. $where = "1=1 ";
  37. //数据排序
  38. $order_str = "id asc";
  39. if(empty($page))
  40. {
  41. $start = 0;
  42. $perpage = 1;
  43. }
  44. else
  45. {
  46. $start = ($page - 1)*$perpage;
  47. }
  48. if($title)
  49. {
  50. $where .= " and title like '%$title%'";
  51. }
  52. //取得信息列表
  53. $info_list = $this->producttitle->find_all($where,'id,title,th',$order_str,$start,$perpage);
  54. $total = $this->producttitle->find_count($where);
  55. $pagenum = ceil($total/$perpage);
  56. $over = $total-($start+$perpage);
  57. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  58. echo json_encode($rows);exit;
  59. }
  60. $this->_Template('producttitle',$this->data);
  61. }
  62. //添加
  63. public function _add()
  64. {
  65. $post = $this->input->post(NULL);
  66. if(isset($post['title']))
  67. {
  68. if($this->producttitle->insert($post))
  69. {
  70. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  71. }
  72. else
  73. {
  74. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  75. }
  76. }
  77. $this->_Template('producttitle_add',$this->data);
  78. }
  79. //修改
  80. public function _edit($arg_array)
  81. {
  82. $post = $this->input->post(NULL);
  83. if(isset($post['id']))
  84. {
  85. $id = $this->input->post('id',true);
  86. if($this->producttitle->save($post,$id))
  87. {
  88. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  89. }
  90. else
  91. {
  92. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  93. }
  94. }
  95. $arg_array = $arg_array[0];
  96. $producttitle = $this->producttitle->read($arg_array);
  97. $this->data['producttitle'] = $producttitle;
  98. $this->_Template('producttitle_edit',$this->data);
  99. }
  100. //删除
  101. public function _del()
  102. {
  103. $post = $this->input->post(NULL, TRUE);
  104. if(isset($post['s']))
  105. {
  106. $id_arr = $this->input->post('s');
  107. $id_arr = explode(',',$id_arr);
  108. if(!$id_arr)
  109. {
  110. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  111. }
  112. //循环删除记录
  113. foreach ($id_arr as $v)
  114. {
  115. $this->producttitle->remove($v);
  116. }
  117. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  118. }
  119. }
  120. }