XF 2.0 getNotice

LPH

Well-known member
This code works but doesn't use NoticesList() or getNotice(). I wasn't sure how to call it. In fact, in general, this is a stickler for me. Notices.php is in the src\XF ..

Code:
$notices = \XF::app()->get('notices');

foreach ( $notices as $noticeItem ) {
    if( $noticeItem['notice_id'] == $instance['noticenumber'] ) {
       echo $noticeItem['message'];
          }
      }

Second Question:
With the above code, the HTML is shown; however, the {name} isn't rendered. This also fails to take into account any options chosen in the XenForo options for Notices. Eventually, the avatar option chosen should show next to the notice.
 
I'm not really clear on what the question is. The "notices" entry in the container is just the raw set of notices. You aren't using anything to do with the NoticeList system.

The NoticeList system is also what does token replacement. Beyond that, rendering choices are handled in the templates.
 
  • Like
Reactions: LPH
As always, thank you for helping. My brain starts to shut down after a few hours of trying to follow the code.

I guess my first question is whether using the get('notices'); is the best way to get the notices.

My second question is how to decide to look into the template system versus the finder system versus simply using get. Maybe that is too general of a question.

Related to my learning:

I'm starting to build a table showing one way to call something in XF1 versus how to do the same in XF2:

XenForo_Application == \XF::app()

\XenForo_Helper_String::wholeWordTrim == \XF::app()->stringFormatter()->wholeWordTrim

\XenForo_Link::buildPublicLink == \XF::app()->router()->buildLink
 
I guess my first question is whether using the get('notices'); is the best way to get the notices.
For the raw notice cache, that's what you need. But as usual, it will depend what you're trying to do.

My second question is how to decide to look into the template system versus the finder system versus simply using get. Maybe that is too general of a question.
It is very general and the answer will certainly be "it depends". I'm not sure where the template system fits in though -- that's a different purpose and would generally be needed for any sort of rendering.
 
  • Like
Reactions: LPH
Back
Top Bottom