Home > Archive Post, ColdFusion > Creating a custom Farcry type

Creating a custom Farcry type

Hi again,

I’ve been delving into the wonderful world of Farcry CMS. I needed to create a custom type and having never created one before didn’t really know where to start. Luckily for me I’m working with one of the ex-developers of Farcry Michael and he stepped me through how to create it. This process is for the latest beta version of Farcry 5 so may be different for other versions of the CMS.

First and foremost you need to need to create a new type cfc in you /webroot/farcry/projects/#projectName#/packages/types directory. I created a CFC called Products(although I think you may be better of leaving it all lower case, more on that later) which contains several properties. The properties contained in this CFC define what is to be contained in the request stObj whenever someone hits/calls the new types page. The products cfc extends the farcry core types cfc and so inherits all the generic stuff like status verison, object id etc properties that are common across all farcry objects. Next I began to include my own custom ’stuff’ that I want specific to that object. I created a title, display method and product type. The title is just a string and the display method goes off and creates a drop down list of all objects in the products directory in the webskin that begin with ‘displayPage’, again more on that later. The product type is a list of allowed types of products. I specified this as a string but it can easily be replaced by a query or you can pull in other Farcry objects. Finally we need an edit function that tells farcry where to look when editing the object in the back-end. I specified that farcry should look in the _Products directory and for edit.cfm. So whenever we are editing an object in the back end Farcry will load up edit.cfm and this page essentially becomes a regular form style page with a little difference as you need to save the changes back to the Farcry object & DB when completed.







	

	
	
	



The edit.cfm is quite long but I’ve edited it a bit and included it anyway.










	
	

	
	













	
	
	



	
	
	
	
 	
	
	
		 

	
	
		
		
		
		

		
		
			
			
			
			
			
			
			
			
			

		
			
		

	
		
		

#errormessage#

#application.rb.getResource("generalInfo")#: #stObj.title#

Now you’ve created your products.cfc log into the farcry backend and go to the Admin tab. Select COAPI management from the dropdown and then select types on the left hand nav. You should now see your newly created products object here ready to be deployed. You can select deploy and your products should be available in the backend. However you need to do one more thing before you can begin to create products in the backend and view them on the front end, you need to define how products are to be displayed on the front end. To do this create a products directory in the /webroot/farcry/products/#appName#/webskin/ and within this create a page called displayPageStandard. Whenever this page is called the stObj struct is passed into the page and you can now access all the properties of this specific product and display it as you wish. So within this page I just dumped the stObj and then created a simple table of the object title and type. Obviously you can do much more complex stuff than this but this is really just a tutorial on how to do it.

Now you should be able to create product objects select a display method and edit them according to your own custom edit.cfm. One problem I never encountered on my Mac but did in staging was that I had created the products cfc with a large “P” and had use the same casing everywhere around the project. No problem there but in staging an error occurred saying that the table ‘products’ couldn’t be found. Looks like Farcry LCASEs the products name when creating the table, Mac’s NFS filesystem was forgiving but on Linux the problem reared it’s head. Had to rename the table manually and it all worked fine again. Perhaps this is just a bug in the beta that will be fixed come the release date.

I wrote this based entirely off my memory do hope I haven’t left anything out!!!

Categories: Archive Post, ColdFusion Tags:
  1. No comments yet.
  1. No trackbacks yet.

Anti-Spam Protection by WP-SpamFree