Created
November 1, 2011 15:09
-
-
Save asgrim/1330741 to your computer and use it in GitHub Desktop.
ZF coding standards
This file contains 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 AdminController extends Zend_Controller_Action | |
{ | |
public function userAction() | |
{ | |
$this->view->headLink()->appendStylesheet("/css/template/form.css"); | |
$this->view->headLink()->appendStylesheet("/css/pages/project_servers.css"); | |
$users = new GD_Model_UsersMapper(); | |
$user = new GD_Model_User(); | |
$form_options = array(); | |
if($this->_getParam('id') > 0) | |
{ | |
$this->view->headTitle('Edit User'); | |
$users->find($this->_getParam('id'), $user); | |
$form_options['current_user'] = $user->getName(); | |
$form = new GDApp_Form_User($form_options); | |
} | |
else | |
{ | |
$this->view->headTitle('Add User'); | |
$form = new GDApp_Form_User(); | |
$form->password->setRequired(true)->setDescription(''); | |
$user->setDateAdded(date("Y-m-d H:i:s")); | |
} | |
$this->view->form = $form; | |
if($this->getRequest()->isPost()) | |
{ | |
if ($form->isValid($this->getRequest()->getParams())) | |
{ | |
if($this->_getParam('password', false)) | |
{ | |
$crypt = new GD_Crypt(); | |
$user->setPassword($crypt->makeHash($this->_getParam('password'))); | |
} | |
$user->setName($this->_getParam('username')); | |
if($this->_getParam('active')) | |
{ | |
$user->enableUser(); | |
} | |
else | |
{ | |
$user->disableUser(); | |
} | |
$user->setAdmin($this->_getParam('admin')); | |
$users->save($user); | |
$this->_redirect('/admin'); | |
} | |
} | |
else | |
{ | |
$data = array( | |
'username' => $user->getName(), | |
'admin' => $user->isAdmin(), | |
'active' => $user->isActive(), | |
); | |
$form->populate($data); | |
} | |
} | |
} |
This file contains 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 AdminController extends Zend_Controller_Action | |
{ | |
public function userAction() | |
{ | |
$this->view->headLink() | |
->appendStylesheet("/css/template/form.css") | |
->appendStylesheet("/css/pages/project_servers.css"); | |
$users = new GD_Model_UsersMapper(); | |
$user = new GD_Model_User(); | |
$formOptions = array(); | |
if ($this->_getParam('id') > 0) { | |
$this->view->headTitle('Edit User'); | |
$users->find($this->_getParam('id'), $user); | |
$formOptions['current_user'] = $user->getName(); | |
$form = new GDApp_Form_User($formOptions); | |
} else { | |
$this->view->headTitle('Add User'); | |
$form = new GDApp_Form_User(); | |
$form->password->setRequired(true)->setDescription(''); | |
$user->setDateAdded(date("Y-m-d H:i:s")); | |
} | |
$this->view->form = $form; | |
if ($this->getRequest()->isPost()) { | |
if ($form->isValid($this->getRequest()->getParams())) { | |
if ($this->_getParam('password', false)) { | |
$crypt = new GD_Crypt(); | |
$has = $crypt->makeHash($this->_getParam('password')); | |
$user->setPassword($hash); | |
} | |
$user->setName($this->_getParam('username')); | |
if ($this->_getParam('active')) { | |
$user->enableUser(); | |
} else { | |
$user->disableUser(); | |
} | |
$user->setAdmin($this->_getParam('admin')); | |
$users->save($user); | |
$this->_redirect('/admin'); | |
} | |
} else { | |
$data = array( | |
'username' => $user->getName(), | |
'admin' => $user->isAdmin(), | |
'active' => $user->isActive(), | |
); | |
$form->populate($data); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment