2

私は現在、Coldfusion アプリケーションのいくつかを更新しており、構造の一部を維持するための良い方法を探しています。

現在、このようなセットアップ

ApplicationRoot/Application.cfc (handles things like login, init etc..)
ApplicationRoot/Admin (I want exact same var's as parent folder, but few extra checks to ensure the user has admin rights)

現在、セットアップは各ディレクトリ内のアプリケーション ファイルで機能します (実際に機能します) が、アプリケーション/セッション スコープなどのすべてを再度宣言することで面倒になります。より良い方法はありますか?

4

3 に答える 3

4

Application.cfcadmin サブディレクトリで、親ディレクトリのサブディレクトリを拡張します。例:

component extends="ApplicationProxy" {

    // eg: if you need to do something different in the local onApplicationStart:
    public void function onApplicactionStart(){
        super.onApplicationStart();
        // stuff that's different from the parent goes here
    }    

    // if there's nothing different for a given handler, then don't have one in here: the super one will still fire

    // otherwise override each handler in a similar fashion to the onApplicationStart above, with:
    // a) a call to its super equivalent
    // b) anything that needs overriding

}

ベースディレクトリにApplicationProxy.cfc、次のように追加します。

component extends="Application" {

}

これは、循環参照のように見えるため、サブルーチンにを含めるApplication.cfcことができないためです。extends="Application"ただし、ベース ディレクトリ内の Application.cfc を識別するより適切な「資格のある」方法はないため、プロキシが必要です。

于 2012-10-01T16:53:49.997 に答える
0

RequestStart()のApplication.cfcで次のようなことを試してみます。

<cffunction name="onRequestStart" returnType="boolean" output="false" hint="I handle page requests." >
  <cfargument name="requestname" type="string" required="true" >

  <cfif FileExists(GetDirectoryFromPath(arguments.requestname) & '/admin.cfm')>
    <cfinclude template="#GetDirectoryFromPath(arguments.requestname)#/admin.cfm">
  </cfif>
</cffunction>

次に、カスタム変数を設定する各ディレクトリに、admin.cfmファイルを配置します。このadmin.cfmファイルには、一連のタグを配置するか、セッション変数とアプリケーション変数を設定する必要があります。

于 2012-10-01T16:41:19.570 に答える
0

チェックを入れて、ユーザーが実行しているディレクトリを確認してから、追加のコードを実行することもできます。たとえば、メインの application.cfc onRequestStart() で、「現在の要求は admin フォルダですか?」と言うことができます。OK、すべてのセキュリティ機能を含む機能 X を実行します。必要に応じて、このコードを追加関数として application.cfc 内に含めることもできます。

または、拡張機能を実行して他の回答のいずれかを使用する場合は、他のコードを実行する各関数に super.function() 呼び出しを配置する必要があります。たとえば、onRequest start では、sub-Application.cfc onRequestStart() の先頭にある super.onRequestStart() を使用して、子が起動する前に親のものを呼び出します。

個人的には、アプリケーションが本当に 1 つしかない場合でも整理しやすい最初の方法を好みます。

于 2012-10-01T16:59:16.173 に答える