Notice.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\user\controller;
  3. use app\base\controller\Base;
  4. class Notice extends Base{
  5. private $noticeModel;
  6. public function _initialize(){
  7. parent::_initialize();
  8. $this->noticeModel = new \app\user\model\Notice();
  9. }
  10. public function index(){
  11. $p = $this->request->get('page', 0);
  12. $nick = $this->request->get('n');
  13. $where = [];
  14. if($nick) $where['title'] = ['like', "%$nick%"];
  15. $info = $this->noticeModel->getInfo($p, $where);
  16. $page = $this->noticeModel->getPage($where);
  17. $this->assign("info", $info);
  18. $this->assign("page", $page);
  19. return $this->fetch();
  20. }
  21. public function edit(){
  22. $id = $this->request->get('id');
  23. $info = $this->noticeModel->getNoticeById($id);
  24. $this->assign("info", $info);
  25. return $this->fetch('edit');
  26. }
  27. public function delete(){
  28. $res = $this->noticeModel->where(['id'=>$this->request->get('id')])->delete();
  29. if($res){
  30. $this->success('删除成功!', 'index');
  31. }else{
  32. $this->error('删除失败!');
  33. }
  34. }
  35. public function save(){
  36. $res = $this->noticeModel->addAndSave();
  37. if($res){
  38. $this->success('保存成功!', 'index');
  39. }else{
  40. $this->error('保存失败!');
  41. }
  42. }
  43. }