0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【ColdFusion】cfcomponent タグ の extends 属性内には変数を使えない

Last updated at Posted at 2019-12-11

cfcomponent タグ の extends 属性内には変数を使えない!

アプリが入っているディレクトリ名'hoge'を後から自由に変更できるように

Application.cfc
<cffunction name="onApplicationStart">
  <cfset Application.app_name = "hoge">
</cffunction>

なんてやって、ソース内のディレクトリ名部分を#Application.app_name#に置換しまくったんですが、継承を使用しているコンポーネントでエラーが出ちゃいました。cfcomponent タグ の extends 属性内には変数を使えないみたいです。

example.cfc
<!--- extends属性内に変数が使えない! --->
<CFCOMPONENT extends="#Application.app_name#.component.MyClass">

同じピリオド記法を使う局面でもcreateObjectや、CFOBJECT タグの component 属性なら変数が使えるのに・・・。

マッピングを使おう!

ググってみたんですが、Extend a CFC using a relative path でなにやらマッピングするといいみたいなことが書かれていたので以下のようにしてみました。

Application.cfc
<cfset This.mappings["/MyApp"]="c:\ColdFusion2018\cfusion\wwwroot\hoge">
example.cfc
<CFCOMPONENT extends="MyApp.component.MyClass">

Application.app_name は使えなかったですが、Application.cfc 内の「hoge」部分を置換すればよいだけなのでこれで解決としました。(目的は Application.cfc 以外を触らずにディレクトリ名を変更することなので)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?