Created
February 17, 2012 09:07
-
-
Save alexander-torosh/1852045 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class UsersController extends Np_CustomController | |
| { | |
| public function listAction() | |
| { | |
| $db = Zend_Db_Table::getDefaultAdapter(); | |
| $select = $db->select() | |
| ->from(array('Users' => 'users')); | |
| $rowSet = $db->query($select); | |
| $result = $rowSet->fetchAll(); | |
| $this->view->test = $result; | |
| } | |
| public function addAction() | |
| { | |
| $form = new Application_Form_Users(); | |
| $form->getElement('submit')->setLabel('Добавить пользователя'); | |
| if ($this->_request->isPost()) { | |
| $formData = $this->_request->getPost(); | |
| if ($form->isValid($formData)) { | |
| $addUser = new Application_Model_DbTable_Users(); | |
| $row = $addUser->createRow(); | |
| $row->login = $form->getValue('login'); | |
| $row->password = $form->getValue('password'); | |
| $row->role = $form->getValue('role'); | |
| $row->save(); | |
| $this->_redirect('/users/list'); | |
| } | |
| } | |
| $this->view->form = $form; | |
| $this->view->title = "Добавить нового пользователя"; | |
| $this->view->headTitle($this->view->title); | |
| } | |
| public function editAction() | |
| { | |
| $request = $this->getRequest(); | |
| $form = new Application_Form_Users(); | |
| $form->getElement('submit')->setLabel('Сохранить изменения'); | |
| $editUser = new Application_Model_DbTable_Users(); | |
| if ($request->isPost()) { | |
| $post = $request->getPost(); | |
| if ($form->isValid($post)) { | |
| $login = $form->getValue('login'); | |
| $row = $editUser->fetchRow('login = "' . $login . '"'); | |
| $row->login = $form->getValue('login'); | |
| $row->password = $form->getValue('password'); | |
| $row->role = $form->getValue('rolee'); | |
| $row->save(); | |
| $this->_redirect('/users/list'); | |
| } | |
| } | |
| $login = $request->getParam('login'); | |
| if ($login) { | |
| $editUser = $editUser->fetchRow('login = "' . $login . '"'); | |
| $form->populate($editUser->toArray()); | |
| } | |
| $this->view->form = $form; | |
| $this->view->title = "Редактировать информацию о пользователе"; | |
| } | |
| public function deleteAction() | |
| { | |
| $request = $this->getRequest(); | |
| $editUser = new Application_Model_DbTable_Users(); | |
| $login = $request->getPost('login'); | |
| if ($request->isPost()) { | |
| $del = $request->getPost('del'); | |
| if ($del == 'Да' && $login) { | |
| $row = $editUser->fetchRow('login = "' . $login . '"'); | |
| $row->delete(); | |
| } | |
| $this->_redirect('/users/list'); | |
| } | |
| $this->view->title = "Удалить пользователя"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment