1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Script to pull notices

Discussion in 'XenForo Development Discussions' started by LPH, Mar 31, 2013.

  1. LPH

    LPH Well-Known Member

    Yesterday I worked on getting the latest resources from the site, today I'd like to get a script for pulling a particular notice. For example, notice 23. However, I'm not sure how to actually display the notice. Now, I know what is below just posts "array" but this is because I wasn't sure of the echo.

            <div class="scrollContainer">
            <div class="PanelContainer">
    /* Script to pull a notice from the XF */
    /** @var $notModel XenForo_Model_Notice */
    $notModel XenForo_Model::create('XenForo_Model_Notice');
    $notices $notModel->getNoticeById(23);
        </div> <!-- End PanelContainer -->
        </div> <!-- End scrollContainer -->
    Update: This code has been updated to show what works. Thank you Chris.
  2. Chris D

    Chris D XenForo Developer Staff Member

    You will want to echo $notice['title'] for the title and $notice['message'] for the message :)

    EDIT: Ah just thought - you probably don't need to loop the resulting $notices array.

    You're using the getNoticeById function which basically returns the entire row for the ID you provide. So you'd just need $notices['title'] and $notices['message']
    LPH likes this.
  3. LPH

    LPH Well-Known Member

    Thanks Chris. I actually tried that and was not getting the message.

    echo $notice['message'];
    retuns "ROaa" into the page.

    whereas what I have above with just the $notice gives

    23ResourcesOur Tablet Resource Manager is just being built. As we transfer files from [URL='http://www.tabletpcpost.com']Tablet PC Post[/URL], feel free to add your own tablet resource.1111a:0:{}a:1:{i:0;a:2:{s:4:"rule";s:10:"controller";s:4:"data";a:2:{s:4:"name";s:37:"XenResource_ControllerPublic_Resource";s:6:"action";s:5:"Index";}}}
    So, I'm not sure why the echo with message isn't working :(
  4. Chris D

    Chris D XenForo Developer Staff Member

    You may have missed my edit.

    There's no need to loop through the $notices array. It only contains one notice, so you just need $notices['message'] and $notices['title']
  5. LPH

    LPH Well-Known Member

    Yeah - I tried to remove the loop earlier - and just tried again. Unfortunately then nothing shows up in WordPress :(
  6. Chris D

    Chris D XenForo Developer Staff Member

    So what do you get if you var_dump($notices) ?
  7. LPH

    LPH Well-Known Member

    Oh freaking --- insert ---- TYPO !

    I have it working now and will update the code in the original post.
    Chris D likes this.
  8. LPH

    LPH Well-Known Member

    And here is an image of the WordPress side showing the Notice. ;)

    Screen Shot 2013-03-31 at 10.57.27 AM.png
    Chris D likes this.
  9. LPH

    LPH Well-Known Member

    I'm back to looking at the notices and see that user_criteria are not included. Plus, the notices cannot be dismissed.

    $notices XenForo_Model::create('XenForo_Model_Notice')->getModelFromCache('XenForo_Model_Notice')->getNoticeById$instance['noticenumber'] );

    A search in the XF code didn't find a way the user_criteria is used with notices. A search on this site didn't return an example of someone using permissions or criteria. Does anyone have an example?

Share This Page