Index.class.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace Cas\Controller\Admin\Category;
  3. use KIF\Core\Request;
  4. use Cas\Controller\Admin\Controller;
  5. use KIF\Page\Page;
  6. use Cas\Dao\Category;
  7. /**
  8. * "分类相关" - "列表"[分类相关信息]
  9. *
  10. * @author rabin
  11. * 页面: "分类信息"列表 doPageList
  12. * 页面: 查看&修改 "分类信息" doPageShow
  13. * 事件: 创建"分类信息" doReqCreate
  14. * 事件: 修改"分类信息" doReqUp
  15. * 事件: 删除"分类信息" doReqDel  
  16. */
  17. class Index extends Controller {
  18. private $objDCategory;
  19. private $operatorData;
  20. /**
  21. *  初始化
  22. */
  23. public function __construct() {
  24. header ( "Content-Type: text/html; charset=utf-8" );
  25. $this->objDCategory = new Category ();
  26. $this->operatorData = $this->getUser ();
  27. }
  28. /**
  29. * 默认
  30. */
  31. public function doDefault() {
  32. }
  33. /**
  34. * 页面: "分类信息"列表
  35. * 地址:http://cas.lishuy.com/?c=Admin_Category_Index&a=PageList
  36. */
  37. public function doPageList() {
  38. $page = Request::varGetInt ( 'page', 1 );
  39. $size = 10;
  40. $offset = ($page - 1) * $size;
  41. $limit = "{$offset},{$size}";
  42. $condition = array ();
  43. $total_num = $this->objDCategory->totals ( $condition );
  44. $url_tpl = Request::schemeDomain () . "?c=Admin_Category_Index&a=PageList";
  45. $url_tpl .= "&page={page}";
  46. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  47. $page_html = $objPage->html ();
  48. $order = 'id desc';
  49. $ids = $this->objDCategory->findIdsBy ( $condition, $limit, $order );
  50. $CategoryData = $this->objDCategory->gets ( $ids );
  51. $this->tpl = 'admin/category/list';
  52. $title = '分类列表';
  53. $this->setOutput('title', $title);
  54. $this->setOutput('menu_active', array('name' => 'categorylist', 'item' => 'list')); //激活菜单
  55. $this->addNavMenu('分类设置');
  56. $this->addNavMenu($title);
  57. $this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据
  58. $this->setOutput ( 'page_html', $page_html ); // 分页Html
  59. $this->setOutput ( 'CategoryData', $CategoryData ); // 当前"分类信息"列表数据
  60. }
  61. /**
  62. * 页面: 查看&修改 "分类信息"
  63. * 地址:http://cas.lishuy.com/?c=Admin_Category_Index&a=PageShow&id=nn
  64. * 参数:id "分类信息"id
  65. */
  66. public function doPageShow() {
  67. $id = Request::g ( 'id' );
  68. $CategoryData = $this->objDCategory->get ( $id );
  69. $this->tpl = 'admin/category/edit';
  70. $title = '编辑分类信息';
  71. $this->setOutput('title', $title);
  72. $this->setOutput('menu_active', array('name' => 'categorylist', 'item' => 'list')); //激活菜单
  73. $this->addNavMenu('分类设置');
  74. $this->addNavMenu('分类列表', Request::schemeDomain() . '/?c=Admin_Category_index&a=PageList');
  75. $this->addNavMenu($title);
  76. $this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据
  77. $this->setOutput ( 'CategoryData', $CategoryData ); // 当前"分类信息"内容
  78. }
  79. /**
  80. * 事件:创建"分类信息"
  81. * 地址:http://cas.lishuy.com/index.php?c=Admin_Category_Index&a=ReqCreate
  82. * 参数:见方法内
  83. */
  84. public function doReqCreate() {
  85. $tableInfo = $_POST;
  86. $operator_uid = $this->operatorData ['uid'];
  87. $info = array_merge($tableInfo, array(
  88. 'operator_uid' => $operator_uid
  89. ));
  90. $tmpResult = $this->objDCategory->add ( $info );
  91. if (!$tmpResult) {
  92. $this->ajax_fail_exit('添加新分类失败');
  93. }
  94. $this->ajax_success_exit();
  95. }
  96. /**
  97. * 事件: 修改"分类信息"
  98. * 地址:http://cas.lishuy.com/index.php?c=Admin_Category_Index&a=ReqUp
  99. * 参数:见方法内
  100. */
  101. public function doReqUp() {
  102. $tableInfo = $_POST;
  103. $id = $tableInfo['id'];
  104. unset($tableInfo['id']);
  105. $operator_uid = $this->operatorData ['uid'];
  106. $info = array_merge($tableInfo, array(
  107. 'operator_uid' => $operator_uid
  108. ));
  109. $tmpResult = $this->objDCategory->modify ( $info, array (
  110. 'id' => $id
  111. ) );
  112. if (!$tmpResult->isSuccess()) {
  113. $this->ajax_fail_exit($tmpResult->getData());
  114. }
  115. $this->ajax_success_exit();
  116. }
  117. /**
  118. * 事件: 删除"分类信息"
  119. * 地址:http://cas.lishuy.com/index.php?c=Admin_Category_Index&a=ReqDel
  120. * 参数:见方法内
  121. */
  122. public function doReqDel() {
  123. $id = Request::p ( 'id' );
  124. $this->objDCategory->delete ( array (
  125. 'id' => $id
  126. ) );
  127. // TODO 根据前端自定义返回结果或跳转
  128. header ( "Location: " . Request::schemeDomain () . "/?c=Admin_Category_Index&a=PageList" );
  129. exit ();
  130. }
  131. public function display() {
  132. return $this->render ();
  133. }
  134. }