Hello experts.
I have in my application file two createobject:
<cfset objcategories = CreateObject("component", "admin.com.categories").init(dsn = "#request.dsn#")>
<cfset objhtaccess = CreateObject("component", "admin.com.createhtaccess").init(dsn = "#request.dsn#")>
The first one is handling all the categories stuff and the second is creating and updating the htaccess file.
Now if i add or update my categories i want to recreate this htaccess file.
f.e.
delete categorie:
<cfset qrydeletecategory = objcategories.fdeletecategory(url.categoryid)>
cffunction:
<cffunction name="fdeletecategory" access="public" returntype="boolean">
<cfargument name="categoryid" type="numeric" required="yes">
<cfquery name = "DeleteCategory" datasource="#variables.dsn#">
DELETE FROM categories
WHERE CategoryID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.categoryid#">
</cfquery>
<!--- CREATE HTACCESS AND SITEMAP ? --->
<cfreturn true>
</cffunction>
For creating the htaccess file:
<cfset qryhtaccess = objhtaccess.writehtaccess(request.rewriteruleformat)>
The question is.
Can i call the writehtaccess function inside the fdeletecategory function?
Is this the right way?
Yes. If it's stateless, there are 3 choices
1) recreate the createhtaccess object every time you call the delete function
ie Use cfinvoke component="admin.com.creat
2) create a new instance inside init() and store it in the variables scope. That means you'll have only 2 instances instead of 1 each time you call the delete function
<cffunction name="init" ..>
<cfargument name="dsn" ...>
<cfset variables.dsn = arguments.dsn>
<cfset variables.htaccess = createObject("admin.com.cr
</cffunction>
3) pass the instance created inside your application file into init() as an argument. Then store it in the variables scope and use that object when you call delete. So you'll only have 1 instance in the entire application
<!--- create htaccess first --->
<cfset objhtaccess = CreateObject("component", "admin.com.createhtaccess"
<!--- pass it in as an argument --->
<cfset objcategories = CreateObject("component", "admin.com.categories").in
<!--- init function of admin.com.categories --->
<cffunction name="init" ..>
<cfargument name="dsn" ...>
<cfargument name="htaccess" ...>
<cfset variables.dsn = arguments.dsn>
<cfset variables.htaccess = arguments.htaccess>
</cffunction>
Use the variables scoped object inside your delete function
<!--- CREATE HTACCESS AND SITEMAP ? --->
<cfset variables.htaccess.callSom
I need only a clarification for case 2.
Honestly I wouldn't use the extends hack unless the components are truly related, which they don't seem to be. If they're not, better to keep them separate and pass in the component using one of the methods above. Preferably #2 or #3