Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class IndexController extends Zend_Controller_Action
- {
- public function init()
- {
- /* Initialize action controller here */
- }
- public function indexAction()
- {
- $user = new Application_Model_DbTable_User();
- $this->view->user = $user->fetchAll();
- $paginator = Zend_Paginator::factory($this->view->user);
- $paginator->setCurrentPageNumber($this->_getParam("page"));
- $paginator->setItemCountPerPage(1);
- $paginator->setPageRange(3);
- // Make paginator available in your views
- $this->view->paginator = $paginator;
- }
- public function addAction()
- {
- $form = new Application_Form_User();
- $form->submit->setLabel('Add');
- $this->view->form = $form;
- $form->username->addValidator('Db_NoRecordExists' ,true, array('table' => 'user','field' => 'username' , 'messages' => 'Record already Exist'));
- if ($this->getRequest()->isPost()) {
- $formData = $this->getRequest()->getPost();
- if ($form->isValid($formData)) {
- $company = $form->getValue('company');
- $username = $form->getValue('username');
- $email = $form->getValue('email_id');
- $password = $form->getValue('password');
- $country = $form->getValue('country');
- $status = $form->getValue('status');
- $user = new Application_Model_DbTable_User();
- $user->addUser($company,$username,$email,$password,$country,$status);
- $this->_helper->redirector('index');
- } else {
- $form->populate($formData);
- }
- }
- }
- public function editAction()
- {
- $form = new Application_Form_User();
- $form->submit->setLabel('Save');
- $this->view->form = $form;
- $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'));
- if ($this->getRequest()->isPost()) {
- $formData = $this->getRequest()->getPost();
- if ($form->isValid($formData)) {
- $id = (int)$form->getValue('id');
- $company = $form->getValue('company');
- $username = $form->getValue('username');
- $email = $form->getValue('email_id');
- $password = $form->getValue('password');
- $country = $form->getValue('country');
- $status = $form->getValue('status');
- $user = new Application_Model_DbTable_User();
- $user->updateUser($id,$company,$username,$email,$password,$country,$status);
- $this->_helper->redirector('index');
- } else {
- $form->populate($formData);
- }
- } else {
- $id = $this->_getParam('id', 0);
- if ($id > 0) {
- $user = new Application_Model_DbTable_User();
- $a=$user->getUser($id);
- $form->populate($a);
- }
- }
- }
- public function deleteAction()
- {
- if ($this->getRequest()->isPost()) {
- $del = $this->getRequest()->getPost('del');
- if ($del == 'Yes') {
- $id = $this->getRequest()->getPost('id');
- $user = new Application_Model_DbTable_User();
- $user->deleteUser($id);
- }
- $this->_helper->redirector('index');
- } else {
- $id = $this->_getParam('id', 0);
- $user = new Application_Model_DbTable_User();
- $this->view->user = $user->getUser($id);
- }
- }
- }
Add Comment
Please, Sign In to add comment