objectBreeze Demo - Creating a Flash user form:
The demo was created to show basic use of objectBreeze with a Flash form. This example does not use many of the powerful features of objectBreeze, and is only intended as a primer.
- Create the following table in your database:
Employee
employeeID int(4) PK identity
fName varchar(20)
lName varchar(20)
email varchar(75)
- In the /objectBreeze Folder, you will find the following files:
Application.cfm
index.cfm
frm.Employee.cfm
lst.Employee.cfm
- Edit Application.cfm lines 6 and 7 to match your datasource and DBType (MSSQL, Oracle, MySQL, PostgreSQL).
- Index.cfm is set up as a quasi-controller (it is just one big case statement). Notice that the default event is main, which will be displayed when you first browse to http://yourdomain/objectBreeze. This event calls lst.Employee.cfm, which displays the employee list. Notice how the queryObject is initialized in main using list(). It is then placed into the vars scope and is accessible from lst.Employee.cfm. This same functionality could be called directly from lst.Employee.cfm instead of using the Index.cfm file and vars scope.
- Add an employee by clicking the Add Employee button on the flash form. This will call frm.Employee.cfm (event=getNewEmployee). Notice that we set a local variable equal to the employee object created in the index.cfm file. Since we are creating a new employee, the object is empty. We default all of the fields in the flash form, and it is ready to be filled out. Complete the form and click Save User.
- When the form is being processed, it calls the actSaveUser event. In the index.cfm file, an object is created and populated, and committed to the database. You are then redirected to the employee list, and your new employee has been created.
- Now, let's edit the employee by highlighting your new employee and clicking Edit Employee. This calls the getEditEmployee event. Notice that it creates a new object, and reads the user information into the object. It then calls the same template we used to add the employee, frm.Employee.cfm (reuse). Edit the user, and click Save Employee. The same event used to create the employee is now used to save the edited employee. When the commit function is called, objectBreeze knows to update the object instead of inserting it. You are once again redirected to the Employee List.
See how easy using objects makes programming? As we all know, clients change requirements all the time during a project. Let's say they want to add Phone to the user record. All we have to do is add the Phone column to our database, add a phone field to our form and viola! Since objectBreeze is created using core class files and does not require you to create templates for your data layer, you now have a phone record in your object without editing DAOs and class files. Could it be any easier?
- Now think ahead. What if we want to add several email addresses? We could normalize the database and create a new table called EmployeeEmail. We could then use the containsMany() function to compound the object. The object still uses the same read and commit functions!
In the example files, the objectBreeze controller is set to APPLICATION.objectBreeze. Put it where you need it (framework/scope).
objectBreeze is a controller found in objectBreeze.assets.cfc.controller.objectBreeze. It is initially set into the Application scope in the example. You can set this anywhere you want, so that you can use this with any framework or scope.