Created
June 8, 2017 12:11
-
-
Save neokoenig/a1e37413a325f185e153610e890b31a9 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
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