Creating Objects with Reactor

To create objects you will use the ReactorFactory object.  The ReactorFactory requires that you pass the path to the config file via it's init() method when you instantiate it.  Here's an example:

 

<!--- create the reactorFactory --->
<cfset Reactor = CreateObject("Component", "reactor.reactorFactory").init(expandPath("reactor.xml")) />

 

You will now have an instance of the ReactorFactory.  This object provides several methods to create objects, including the following:

 

 

The first thing I think that most people will want to do is simply list data from their database.  We added a record to the User table above, let's go ahead and list it out now.

 

To do this, we'll need to create a gateway object using the ReactorFactory we created above.

 

<!--- create a userGateway --->
<cfset UserGateway = Reactor.createGateway("User") />

 

Gateway Objects provide a getAll() method (among others) which returns all the records in the table.  The following code gets all of the records in the User table and dumps it out.

 

<!--- get all records --->
<cfset qUsers = UserGateway.getAll() />
<!--- dump the results --->
<cfdump var="#qUsers#" />

 

Here are the results:

 

For a complete list of Gateway methods, see the Gateway Objects section.