开发者

Function access in ColdFusion

开发者 https://www.devze.com 2023-02-08 05:47 出处:网络
开发者_如何学编程Is there a way to access functions through inheritance without setting function access to public?

开发者_如何学编程Is there a way to access functions through inheritance without setting function access to public?

For example: I have Foo.cfc and it extends Bar.cfc. If I want to call a Bar.cfc function from Foo.cfc, I have to set the function access to public.

If I set the function access to private, then it's only accessible from Foo.cfc. Is there no "intermediate" access level that is not quite public but not strictly private? i.e. it allows access through inheritance only...


Are you using the keyword super? Because private methods should be available to sub components like Foo.cfc.

Foo.cfc

<cfcomponent extends="Bar">
    .....
    <cffunction name="fooMethod" access="public" ...>
         <cfreturn super.nameOfAMethodInBarCFC() />
    </cffunction>
</cfcomponent>    


If I set the function access to private, then it's only accessible from Foo.cfc

NOT TRUE! private access level in ColdFusion is same as protected in Java, so you can still call that private method of Bar from Foo


You need to set the access property in cffunction to package. That will allow it to be accessed by any component that extends the component.

0

精彩评论

暂无评论...
验证码 换一张
取 消