Last active
September 30, 2015 11:07
-
-
Save chrisdpeters/1776941 to your computer and use it in GitHub Desktop.
How to Build an Admin Section in CFWheels http://www.chrisdpeters.com/cfwheels-how-to-build-admin-section/
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
component extends="Controller" { | |
//----------------------------------------------------- | |
// Public | |
function init() { | |
filters(through="authenticate"); | |
} | |
//----------------------------------------------------- | |
// Filters | |
private function authenticate() { | |
if(!StructKeyExists(session, "user") { | |
redirectTo(controller="sessions", action="new"); | |
} | |
else { | |
loggedInUser = model("adminUser").findByKey(session.user.id); | |
} | |
} | |
} |
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
component extends="AdminController" { | |
//----------------------------------------------------- | |
// Public | |
function init() { | |
// Be sure to call the parent constructor if you override `init()` | |
super.init(); | |
} | |
function index() { | |
adminUsers = model("adminUser").findAll(order="lastName,firstName"); | |
} | |
} |
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
<cfoutput> | |
<!--- Links to /admin/events ---> | |
#linkTo(text="List Events", route="adminEvents")# | |
<!--- Links to /admin/events/new ---> | |
#linkTo(text="Add an Event", route="adminEvents", action="new")# | |
<!--- Links to /admin/events/view/78 (for example) ---> | |
#linkTo(text="Next Event", route="adminEvents", action="view", key=nextEventId)# | |
<!--- Bonus: Always link to the home page like this! | |
Never link to controller="main", action="home" because you'll get duplicate | |
content at `/` and at `/main/home` ---> | |
#linkTo(text="Home", route="home")# | |
</cfoutput> |
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
<cfscript> | |
// Admin users | |
addRoute(name="adminUsers", pattern="admin/users/[action]/[key]", controller="adminUsers", action="index"); | |
addRoute(name="adminUsers", pattern="admin/users/[action]", controller="adminUsers", action="index"); | |
addRoute(name="adminUsers", pattern="admin/users", controller="adminUsers", action="index"); | |
// Admin events | |
addRoute(name="adminEvents", pattern="admin/events/[action]/[key]", controller="adminEvents", action="index"); | |
addRoute(name="adminEvents", pattern="admin/events/[action]", controller="adminEvents", action="index"); | |
addRoute(name="adminEvents", pattern="admin/events", controller="adminEvents", action="index"); | |
// Admin home | |
addRoute(name="admin", pattern="admin", controller="admin", action="index"); | |
// Site home page | |
addRoute(name="home", pattern="", controller="main", action="home"); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment