2014-12-18 1 views
4

아무도 문제를 말해 줄 수 있습니까? 일부 .cfm 파일을 실행하려고 시도했지만 cfcomponent를 제외한 cffunction의 효과를 트리거하지 않습니다? 내가 놓친 게 있니? 누구든지 내게 설명 할 수 있니?apllication.cfc가 기본 cffunction을 실행하지 않습니까? Coldfusion

<cfcomponent> 
    <cfset THIS.Name = "formdemo"> 
    <cfset THIS.SessionManagement = true> 
    <cfset This.Sessiontimeout="#createtimespan(0,0,20,0)#"> 
    <cfset This.applicationtimeout="#createtimespan(5,0,0,0)#"> 
    --Entered cfcomponent-- 
    <cffunction name="onApplicationStart" returnType="boolean" output="false"> 
    --Entered Application Start-- 
    <cfset application.portfolioUploadRoot = "ram:///portfoliouploads"> 
    <cfif not directoryExists(application.portfolioUploadRoot)> 
     <cfdirectory action="create" directory="#application.portfolioUploadRoot#"> 
    </cfif> 
    <cfreturn true> 
    </cffunction> 
    <cffunction name="onSessionStart" returnType="void" output="false"> 
    --Entered Session Start-- 
    <cfset session.myuploadroot = application.portfolioUploadRoot & "/" & replace(createUUID(), "-", "_", "all")> 
    <cfif not directoryExists(session.myuploadroot)> 
     <cfdirectory action="create" directory="#session.myuploadroot#"> 
    </cfif> 
    </cffunction> 
    <cffunction name="onApplicationEnd" returnType="void" output="false"> 
    --Entered Application End-- 
    <cfargument name="applicationScope" required="true"> 
    <cfif directoryExists(arguments.applicationScope.portfolioUploadRoot)> 
     <cfdirectory action="delete" recurse="true" directory="#arguments.applicationScope.portfolioUploadRoot#"> 
    </cfif> 
    </cffunction> 
    <cffunction name="onSessionEnd" returnType="void" output="false"> 
    --Entered Session End-- 
    <cfargument name="sessionScope" type="struct" required="true"> 
    <cfargument name="appScope" type="struct" required="false"> 
    <cfif directoryExists(arguments.sessionScope.myuploadroot)> 
     <cfdirectory action="delete" recurse="true" directory="#arguments.sessionScope.myuploadroot#"> 
    </cfif> 
    </cffunction> 
</cfcomponent> 

결과에는 cfmpage.cfm 시작 부분에 "--Entered cfcomponent--"만 표시됩니다.

cfmpage.cfm : 예상대로 그것은하고있다

<cfparam name="form.textname" default=""> 
<cfparam name="form.textemail" default=""> 
<cfparam name="form.docattach" default=""> 
<cfif structKeyExists(form, "Submit")> 
<cfset form.textname = trim(htmlEditFormat(form.textname))> 
<cfset form.textemail = trim(htmlEditFormat(form.textemail))> 
<cflocation url="formcomplete.cfm" addToken="false"> 
</cfif> 
<!DOCTYPE html> 
<html> 
    <head> 
    ... 
    </head> 
    <body> 
    <form method="post" enctype="multipart/form-data"> 
     <cfoutput> 
     <input id="textname" name="textname" type="text" class="input-large" required="" value="#form.textname#"> 
     <input id="textemail" name="textemail" type="text" class="input-large" required="" value="#form.textemail#"> 
     </cfoutput> 
    </form> 
    </body> 
</html> 

답변

3

.

onApplicationStart -- Runs when ColdFusion receives the first request for a page in the application. 
    For this, to easily see this, you can try changing the name of the application, then 
    visit a page within. 

onSessionStart -- Only run upon the first visit within the session. If you wait til after the 
    timeout and then come back, you'll see this. Changing the application name will should also 
    retrigger this. 

onSessionEnd -- Run when the session ends. It will trigger after the timeout, it's used so that 
    you can clean up activity. For instance, if you're using something like Application.NumberOnline. 
    OnSessionEnd can substract one (where onSessionStart) can add one. 

onApplicationEnd -- Runs when the application timeout occurs or the server is shutting down. 

페이지를 방문하는 동안 해당 이벤트를 볼 수 없으므로 후자의 두 텍스트는 화면에 텍스트를 표시하지 않습니다. 그러나 수동으로 호출하여 효과를 트리거 할 수는 있습니다. 그러나 원하는 경우 이러한 작업을 기록 할 수 있습니다. 이 방식으로, 예를 들어,의 cflog 사용할 수 있습니다 :

<cffunction name="onApplicationEnd"> 
    <cfargument name="ApplicationScope" required=true/> 
    <cflog file="#This.Name#" type="Information" 
     text="Application #Arguments.ApplicationScope.applicationname# Ended" > 
</cffunction> 

을 말해 :가 이벤트를 트리거하기 때문에

<cfscript> 
    ap  = createObject("component","Application"); 
    ap.onSessionEnd(session,application); 
</cfscript> 

텍스트를 표시합니다.

마지막으로 각 페이지에서 어떤 일이 일어나길 원한다면 onRequestStart와 onRequestEnd 또는 onRequest가 좋은 옵션입니다. OnRequest는 페이지 주위를 감싸는 메서드이므로 동일한 요청에서 머리글과 바닥 글 작업을 수행 할 수 있지만 요청의 시작과 끝에서 onRequestStart/onRequestEnd를 실행하면 파일을 명시 적으로 포함해야합니다.

호출 동작 방법의 순서

  • onSessionStart (제 1 세션 활동에 실행)
  • onRequestStart
  • onRequest
  • onRequestEnd
  • (1 애플리케이션 활동 실행)

    1. onApplicationStart 인

    L 천만히 말해서 함수가 호출되지 않으면 함수는 실행되지 않습니다. 이것은 자신이 작성한 함수에도 적용됩니다.

    <cfscript> 
        function foo() { 
        writeoutput("bar"); 
        } 
    </cfscript> 
    

    <cfoutput>#foo()#</cfoutput>과 같은 것을 시도 할 때까지 아무 것도하지 않습니다.

    "기본 기능"의 경우, 이는 CF가 특정 지점에서 호출하는 특수 기능/메소드입니다.

    +5

    "이것들을 트리거하면 다음 페이지를 새로 고칠 때 해당 시작 부분이 트리거되어야합니다." 사실이 아니다. 이벤트 핸들러를 호출해도 실제 * 이벤트 *는 발생하지 않습니다. JS에서 'onclick' 핸들러를 호출하면 마우스 버튼이 눌러지지 않습니다. 아닙니다. 다음을 읽으면 도움이 될 것입니다. http://blog.adamcameron.me/2012/07/difference-between-events-and-event.html –

    +0

    @AdamCameron 물론 맞습니다. 나는 그것을 말하지 말았어야했다. 내가 실험 해본 적은 없지만, 이벤트 핸들러가 이벤트를 유발하지 않는다는 것이 옳은 것입니다. 잠시 전에 전화로 고칠 수있었습니다. –

    관련 문제