Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

$Sender->DiscussionID vs $Sender->EventArguments['Discussion']->DiscussionID

edited January 2011 in Vanilla 2.0 - 2.8
I'm a little confused about these two. I needed to set a plugin's class property and had to perform a SQL query using the current DiscussionID. By trial and error I discovered that I need to use $Sender->DiscussionID with, for lack of a better word, "constructor" events (like DiscussionController_Render_Before) and Sender->EventArguments['Discussion']->DiscussionID with regular events.

Can someone tell me what's the difference and why do they return different values at different stages of execution?

Comments

  • I think it all just comes down to the way the events are called. When the events are called from an object that has context, e.g. a discussion controller, then the discussion ID is very likely to be in the Sender (since the Sender is the controller that called the event).

    When events are called from more generic places, such as theme templates or generic helper functions, then there is less context - values such as the discussion ID are more likely to only exist as variables in the caller, and so need to be passed into the event as EventArguments in order for the event to see them.

    Similarly, if an event is called up from a controller (Comments, say) in a loop, then the ID for the loop will likely be passed in as an EventArgument.

    That's my observation at least, but I don't think there is any hard and fast rule. It just needs some inspection of the Sender code.
  • LincLinc Detroit Admin
    edited January 2011
    Yeah, generally EventArguments is used by fired events to pass along additional variables that otherwise wouldn't exist as properties of the object being passed as the $Sender. It's an ad hoc way of providing more data as it's needed.
  • edited January 2011
    Thanks for the replies guys.
    That's my observation at least, but I don't think there is any hard and fast rule. It just needs some inspection of the Sender code.
    So basically print_r and echos?
  • TimTim Operations Vanilla Staff
    Yes. And don't be afraid to look for the FireEvent() call in your IDE and go and see what is being assigned to EventArguments. That is usually the best way to see whats going on.

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • Im trying to get discusision id on base render without any luck :(

  • @NabUser start a new discussion

    grep is your friend.

Sign In or Register to comment.