User.php 963 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\user\controller;
  3. use app\base\controller\Base;
  4. class User extends Base{
  5. private $userModel;
  6. public function _initialize(){
  7. parent::_initialize();
  8. $this->userModel = new \app\user\model\User();
  9. }
  10. public function index(){
  11. $p = $this->request->get('page', 0);
  12. $nick = $this->request->get('n');
  13. $where = [];
  14. if($nick) $where['nickname'] = ['like', "%$nick%"];
  15. $info = $this->userModel->getInfo($p, $where);
  16. $page = $this->userModel->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->adminModel->getAdminById($id);
  24. $this->assign("info", $info);
  25. return $this->fetch('edit');
  26. }
  27. public function save(){
  28. $res = $this->adminModel->addAndSave();
  29. if($res){
  30. $this->success('保存成功!', 'index');
  31. }else{
  32. $this->error('保存失败!');
  33. }
  34. }
  35. }