-
-
Save zunnar/22f07a631408254e2f08 to your computer and use it in GitHub Desktop.
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
public function editAction($id) | |
{ | |
$request = $this->request; | |
if (!$request->isPost()) { | |
$id = $this->filter->sanitize($id, array("int")); | |
$accounts = Accounts::findFirst('id="' . $id . '"'); | |
if (!$accounts) { | |
$this->flash->error("Account was not found"); | |
return $this->forward("accounts/index"); | |
} | |
$this->view->setVar("id", $accounts->id); | |
Tag::displayTo("id", $accounts->id); | |
Tag::displayTo("user", $accounts->user); | |
Tag::displayTo("pwd", $accounts->pwd); | |
Tag::displayTo("group", $accounts->group); | |
Tag::displayTo("au", $accounts->au); | |
Tag::displayTo("ident", $accounts->ident); | |
Tag::displayTo("numusers", $accounts->numusers); | |
Tag::displayTo("penalty", $accounts->penalty); | |
} | |
} | |
public function saveAction() | |
{ | |
$request = $this->request; | |
if (!$request->isPost()) { | |
return $this->forward("accounts/index"); | |
} | |
$id = $request->getPost("id", "int"); | |
$accounts = Accounts::findFirst("id='$id'"); | |
if ($accounts == false) { | |
$this->flash->error("Account does not exist ".$id); | |
return $this->forward("accounts/index"); | |
} | |
$accounts->id = $request->getPost("id", "int"); | |
$accounts->user = $request->getPost("user"); | |
$accounts->pwd = $request->getPost("pwd"); | |
$accounts->group = trim($request->getPost("group")); | |
$accounts->au = trim($request->getPost("au")); | |
$accounts->ident = trim($request->getPost("ident")); | |
$accounts->numusers = $request->getPost("numusers"); | |
$accounts->penalty = $request->getPost("penalty"); | |
if (!$accounts->save()) { | |
foreach ($accounts->getMessages() as $message) { | |
$this->flash->error((string) $message); | |
} | |
return $this->forward("accounts/edit".$accounts->id); | |
} else { | |
$this->flash->success("Account was successfully updated"); | |
return $this->forward("accounts/index"); | |
} | |
} |
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
public function validation() | |
{ | |
$this->validate(new UniquenessValidator(array( | |
'field' => 'user', | |
'message' => 'Sorry, That username is already taken' | |
))); | |
$this->validate(new NumericalityValidator(array( | |
'field' => 'numusers', | |
'message' => 'Sorry, Number of users wrong' | |
))); | |
$this->validate(new NumericalityValidator(array( | |
'field' => 'penalty', | |
'message' => 'Sorry, Penalty value is wrong' | |
))); | |
$this->validate(new RegexValidator(array( | |
'field' => 'ident', | |
'pattern' => '/([0-9]{4}:[0-9]{6},?){1,}/' | |
))); | |
if ($this->validationHasFailed() == true) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment