Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
router
.post( "photos/", "photos.create" )
.get( "photos/", "photos.index" )
.delete( "photos/", "photos.remove" ); ____ _ _ ____
/ ___|___ | | __| | __ ) _____ __
| | / _ \| |/ _` | _ \ / _ \ \/ /
| |__| (_) | | (_| | |_) | (_) > <
\____\___/|_|\__,_|____/ \___/_/\_\<major>.<minor>.<patch>coldbox = {
jsonPayloadToRC = true
}moduleSettings = {
htmlHelper = {
// Base path for loading JavaScript files
js_path = "",
// Base path for loading CSS files
css_path = "",
// Auto-XSS encode values when using the HTML Helper output methods
encodeValues = false
}
}getCurrentModule() instead.module:handlerhandler<!-- Before -->
<a href="#event.buildLink( linkTo="/about/us" )#">About Us</a>
<!-- After -->
<a href="#event.buildLink( to="/about/us" )#">About Us</a>// Datasource definitions
datasources = {
mydsn = {
type = "mysql",
username = "luis",
name = "mydsn"
}
}// Injections
property name="dsn" inject="coldbox:datasource:mydsn"// Settings
settings = {
mydsn = {
type = "mysql",
username = "luis",
name = "mydsn"
}
}// Injections
property name="dsn" inject="coldbox:setting:mydsn"public any function init( required any injector ) output="false"{
public any function process( required definition, targetObject ) output="false"{public any function init( required any injector ) {
public any function process( required definition, targetObject ) {appendToBuffer( generatedHTML );buffer.append( generatedHTML );
{
"name" : "Jon Clausen",
"type" : "awesomeness",
"data" : [ 1,2,3 ]
}// Global flag to denote if we are in mid reinit or not.
cfparam( name="application.fwReinit", default =false );
// Fail fast so users coming in during a reinit just get a please try again message.
if( application.fwReinit ){
// Closure or UDF
if( isClosure( variables.COLDBOX_FAIL_FAST ) || isCustomFunction( variables.COLDBOX_FAIL_FAST ) ){
variables.COLDBOX_FAIL_FAST();
}
// Core Fail Fast Option
else if( isBoolean( variables.COLDBOX_FAIL_FAST ) && variables.COLDBOX_FAIL_FAST ){
writeOutput( 'Oops! Seems ColdBox is still not ready to serve requests, please try again.' );
// You don't have to return a 500, I just did this so JMeter would report it differently than a 200
cfheader( statusCode="503", statustext="ColdBox Not Available Yet!" );
}
return false;
}


/**
* Executes internal named routes with or without parameters. If the named route is not found or the route has no event to execute then this method will throw an `InvalidArgumentException`.
* If you need a route from a module then append the module address: `@moduleName` or prefix it like in run event calls `moduleName:routeName` in order to find the right route.
* The route params will be passed to events as action arguments much how eventArguments work.
*
* @name The name of the route
* @params The parameters of the route to replace
* @cache Cached the output of the runnable execution, defaults to false. A unique key will be created according to event string + arguments.
* @cacheTimeout The time in minutes to cache the results
* @cacheLastAccessTimeout The time in minutes the results will be removed from cache if idle or requested
* @cacheSuffix The suffix to add into the cache entry for this event rendering
* @cacheProvider The provider to cache this event rendering in, defaults to 'template'
* @prePostExempt If true, pre/post handlers will not be fired. Defaults to false
*
* @throws InvalidArgumentException
*/
any function runRoute(
required name,
struct params={},
boolean cache=false,
cacheTimeout="",
cacheLastAccessTimeout="",
cacheSuffix="",
cacheProvider="template",
boolean prePostExempt=false
)// Process a single mapping immediately
map( name ).process();
// Process all mappings in the mapDiretory() call
mapDirectory( packagePath="my.path", process=true )
mapDirectory( "my.path" ).process();
// Map all models in a module via the this.autoProcessModels in the ModuleConfig.cfc
this.autoProcessModels = true
resources(
pattern="/site/:siteId/agents",
resource="agents"
);getOnly( keys, private=false ) method to allow for retrieval of certain keys only from the public or private request contexts. Great for functional programming.sendFile() method.getStatusCode()execute()this.inheritEntryPoint = true+ modules_app
+ api
+ modules_app
+ v1
+ modules_app
+ usersapi - this.entryPoint = /api
v1 - this.entryPoint = /v1
users - this.entryPoint = /userscors = getInstance( "@cors" )setFullRewrites( true ); // defaults to false.// Create a named route
addRoute(
pattern = "/user/:username/:page",
name = "user_detail"
);
// Same for modules
routes = [
{
pattern = "/detail/:username/:page",
name = "user_detail"
}
];<a href="#event.route( name="user_detail", params={ username="luis", page="1" } )#>User Details</a>/**
* Builds links to named routes with or without parameters. If the named route is not found, this method will throw an `InvalidArgumentException`.
* If you need a route from a module then append the module address: `@moduleName` in order to find the right route.
*
* @name The name of the route
* @params The parameters of the route to replace
* @ssl Turn SSL on/off or detect it by default
*
* @throws InvalidArgumentException
*/
string function route( required name, struct params={}, boolean ssl )// Creates all resources that point to a photos event handler by convention
resources( "photos" );
// Register multiple resources either as strings or arrays
resources( "photos,users,contacts" )
resources( [ "photos" , "users", "contacts" ] );
// Register multiple fluently
resources( "photos" )
.resources( "users" )
.resources( "contacts" );
// Creates all resources to the event handler of choice instead of convention
resources( route="photos", handler="MyPhotoHandler" );
// All resources in a module
resources( route="photos", handler="photos", module="api" );
// Resources in a ModuleConfig
resources = [
{ resource="photos" },
{ resource="users", handler="user" }
];/**
* Create all RESTful routes for a resource. It will provide automagic mappings between HTTP verbs and URLs to event handlers and actions.
* By convention, the name of the resource maps to the name of the event handler.
* Example: `resource = photos` Then we will create the following routes:
* - `/photos` : `GET` -> `photos.index` Display a list of photos
* - `/photos/new` : `GET` -> `photos.new` Returns an HTML form for creating a new photo
* - `/photos` : `POST` -> `photos.create` Create a new photo
* - `/photos/:id` : `GET` -> `photos.show` Display a specific photo
* - `/photos/:id/edit` : `GET` -> `photos.edit` Return an HTML form for editing a photo
* - `/photos/:id` : `POST/PUT/PATCH` -> `photos.update` Update a specific photo
* - `/photos/:id` : `DELETE` -> `photos.delete` Delete a specific photo
*
* @resource The name of a single resource or a list of resources or an array of resources
* @handler The handler for the route. Defaults to the resource name.
* @parameterName The name of the id/parameter for the resource. Defaults to `id`.
* @only Limit routes created with only this list or array of actions, e.g. "index,show"
* @except Exclude routes with an except list or array of actions, e.g. "show"
* @module If passed, the module these resources will be attached to.
* @namespace If passed, the namespace these resources will be attached to.
*/
function resources(
required resource,
handler=arguments.resource,
parameterName="id",
only=[],
except=[],
string module="",
string namespace=""
)this.EVENT_CACHE_SUFFIX = function( eventHandlerBean ){
return "a localized string, etc";
};function index( event, rc, prc ) cache=true cacheProvider=couchbase{
}function data( event, rc, prc ){
return [1,2,3];
}
function data( event, rc, prc ){
return myservice.getQuery();
}function data( event, rc, prc ) renderdata="xml"{
return [1,2,3];
}
function data( event, rc, prc ) renderdata="pdf"{
event.setView( "users/index" );
}component renderdata="json"{
}event.setView(
view = "users/detail",
args = { data = userData, border = false },
layout = "main",
name = "userDetail"
);
event.setView(
view = "users/banner",
args = { data = userData },
name = "userBanner"
);<div id="banner">#renderView( name="userBanner" )#</div>
<div id="detail">#renderView( name="userDetail" )#</div>