Neptune 1.0 Beta 3 Documentation: MVC and Controllers

Neptune Information

Download from RIA Forge

MVC and Controllers

Neptune is (in part) an MVC framework, but the Model View and Controller division are done differently than in most frameworks. We have already covered the view portion (Layout Components and .cfm files) and the model portion (service CFCs), but we haven't covered the controller portion yet.

Page Controller

So far we have relied on the built-in page controller. This handles connections between the view and the model and sets several convenient default attributes for cf_sebForm and cf_sebTable. Sometimes, however, we may want to change those values or add more complicated connections between the view and model layers.

Here is the basic page controller to which other code could be added:

<cfcomponent extends="_config.PageController" output="no">

<cffunction name="loadData" access="public" returntype="struct" output="no">
	
	<cfset var vars = Super.loadData()>
	
	<cfreturn vars>
</cffunction>

</cfcomponent>

Note that for our contact-edit.cfm, the page controller has a built-in "saveContact" method. We could add our own here if we wanted to provide some more complicated translation:

<cfcomponent extends="_config.PageController" output="no">

<cffunction name="loadData" access="public" returntype="struct" output="no">
	
	<cfset var vars = Super.loadData()>
	
	<cfreturn vars>
</cffunction>

<cffunction name="saveContact" access="public" returntype="string" output="no">
	
	<cfreturn variables.Contacts.saveContact(argumentCollection=arguments)>
</cffunction>

</cfcomponent>

MVC Guidelines

Keep the following considerations in mind to keep your application a proper MVC application (the impact on maintainability of following these guidelines is difficult to overstate):

Model

Service-level components

  • Can interact with the database (directly or through DataMgr).
  • Should not have any display output.
  • Should not have any page-specific logic
View

Layout Components and .cfm files

  • Should not interact with the database (directly or through DataMgr).
  • Should not have any display output.
  • Should not have any logic
Controller

Page Controllers

  • Should not interact with the database (directly or through DataMgr).
  • Should have display output.
  • Should have page-specific logic

Next: Installation and Generation