Skip to content

Instantly share code, notes, and snippets.

@neokoenig
Created June 8, 2017 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neokoenig/a1e37413a325f185e153610e890b31a9 to your computer and use it in GitHub Desktop.
Save neokoenig/a1e37413a325f185e153610e890b31a9 to your computer and use it in GitHub Desktop.
component extends="Admin" {
function config() {
super.config();
verifies(except="index,new,create", params="key", paramsTypes="integer", handler="objectNotFound");
verifies(post=true, only="create,update,delete");
}
function index() {
users=model("user").findAll();
}
function show() {
user=model("user").findByKey(params.key);
if(!isObject(user)){objectNotFound();}
}
function new() {
user=model("user").new();
}
function create() {
user=model("user").new(params.user);
if(!user.save()){
renderView(action="new");
} else {
redirectTo(action="index", success="User #user.firstname# #user.lastname# successfully created");
}
}
function edit() {
user=model("user").findByKey(params.key);
}
function update() {
user=model("user").findByKey(params.key);
if(user.update(params.user)){
redirectTo(action="index", success="User #user.firstname# #user.lastname# successfully updated");
} else {
renderView(action="edit");
}
}
function delete() {
user=model("user").deleteByKey(params.key);
redirectTo(action="index", success="User successfully Deleted");
}
function objectNotFound() {
redirectTo(action="index", error="That User wasn't found");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment