Guest User

Untitled

a guest
Jan 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. <?php
  2.  
  3. class IndexController extends Zend_Controller_Action
  4. {
  5.  
  6. public function init()
  7. {
  8. /* Initialize action controller here */
  9. }
  10.  
  11. public function indexAction()
  12. {
  13.  
  14. $user = new Application_Model_DbTable_User();
  15. $this->view->user = $user->fetchAll();
  16. $paginator = Zend_Paginator::factory($this->view->user);
  17. $paginator->setCurrentPageNumber($this->_getParam("page"));
  18. $paginator->setItemCountPerPage(1);
  19. $paginator->setPageRange(3);
  20.  
  21. // Make paginator available in your views
  22. $this->view->paginator = $paginator;
  23.  
  24. }
  25.  
  26. public function addAction()
  27. {
  28. $form = new Application_Form_User();
  29. $form->submit->setLabel('Add');
  30. $this->view->form = $form;
  31. $form->username->addValidator('Db_NoRecordExists' ,true, array('table' => 'user','field' => 'username' , 'messages' => 'Record already Exist'));
  32.  
  33. if ($this->getRequest()->isPost()) {
  34. $formData = $this->getRequest()->getPost();
  35. if ($form->isValid($formData)) {
  36. $company = $form->getValue('company');
  37. $username = $form->getValue('username');
  38. $email = $form->getValue('email_id');
  39. $password = $form->getValue('password');
  40. $country = $form->getValue('country');
  41. $status = $form->getValue('status');
  42. $user = new Application_Model_DbTable_User();
  43. $user->addUser($company,$username,$email,$password,$country,$status);
  44.  
  45. $this->_helper->redirector('index');
  46. } else {
  47. $form->populate($formData);
  48. }
  49. }
  50.  
  51. }
  52.  
  53. public function editAction()
  54. {
  55. $form = new Application_Form_User();
  56. $form->submit->setLabel('Save');
  57. $this->view->form = $form;
  58.  
  59. $form->username->addValidator('Db_NoRecordExists' ,true, array('table' => 'user','field' => 'username' , 'exclude' => array('field' => 'id','value' => trim(addslashes($this->_getparam('id')))),'messages' => 'Record already Exist'));
  60.  
  61. if ($this->getRequest()->isPost()) {
  62. $formData = $this->getRequest()->getPost();
  63. if ($form->isValid($formData)) {
  64. $id = (int)$form->getValue('id');
  65. $company = $form->getValue('company');
  66. $username = $form->getValue('username');
  67. $email = $form->getValue('email_id');
  68. $password = $form->getValue('password');
  69. $country = $form->getValue('country');
  70. $status = $form->getValue('status');
  71. $user = new Application_Model_DbTable_User();
  72. $user->updateUser($id,$company,$username,$email,$password,$country,$status);
  73.  
  74. $this->_helper->redirector('index');
  75. } else {
  76. $form->populate($formData);
  77. }
  78. } else {
  79. $id = $this->_getParam('id', 0);
  80. if ($id > 0) {
  81. $user = new Application_Model_DbTable_User();
  82. $a=$user->getUser($id);
  83. $form->populate($a);
  84. }
  85. }
  86.  
  87. }
  88.  
  89. public function deleteAction()
  90. {
  91. if ($this->getRequest()->isPost()) {
  92. $del = $this->getRequest()->getPost('del');
  93. if ($del == 'Yes') {
  94. $id = $this->getRequest()->getPost('id');
  95. $user = new Application_Model_DbTable_User();
  96. $user->deleteUser($id);
  97. }
  98. $this->_helper->redirector('index');
  99. } else {
  100. $id = $this->_getParam('id', 0);
  101. $user = new Application_Model_DbTable_User();
  102. $this->view->user = $user->getUser($id);
  103. }
  104. }
  105.  
  106.  
  107. }
Add Comment
Please, Sign In to add comment