Skip to Content

MVC: Can View be the Controller's friend?

Whenever I want to use a method or attribute of a controller inside a view (<%=controller->attribute%>), the attribute has to be public. I often run into the case that an attribute is only used inside the controller AND on the view, but nowhere else. If the view would be a class, I could add it as a "friend" to the controller class and the view would have access to the attribute although it's private. But since a view is not a class, I guess there is not much I can do except setting the attributes to public, right?

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Nov 24, 2004 at 04:05 PM

    Ironically your view is a class. However it is dynamically generated and has a name something like the following - CL_O2AF3WTE8WB4I3SOYJU1VR1ZWQ5. So I don't think there would be any opportunity to setup a friend relationship.

    I'm curious though, I almost never create attributes in my Controller (and when I do they are always private or protected). If I want to share any data with my view, I do that through my Model Class. Perhaps this is just a matter of style, but I was wondering what benefits you see in sharing attributes from the controller to the view?

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.