Script to pull notices

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.

PHP:
        <div class="scrollContainer">
        <div class="PanelContainer">
    <?php
 
/* Script to pull a notice from the XF */
 
/** @var $notModel XenForo_Model_Notice */
$notModel = XenForo_Model::create('XenForo_Model_Notice');
 
$notices = $notModel->getNoticeById(23);
 
echo $notices['message'];
 
?>
    </div> <!-- End PanelContainer -->
    </div> <!-- End scrollContainer -->

Update: This code has been updated to show what works. Thank you Chris.
 
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']
 
  • Like
Reactions: LPH
Thanks Chris. I actually tried that and was not getting the message.

PHP:
echo $notice['message'];

retuns "ROaa" into the page.

whereas what I have above with just the $notice gives

Code:
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 :(
 
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']
 
Yeah - I tried to remove the loop earlier - and just tried again. Unfortunately then nothing shows up in WordPress :(
 
Oh freaking --- insert ---- TYPO !

I have it working now and will update the code in the original post.
 
I'm back to looking at the notices and see that user_criteria are not included. Plus, the notices cannot be dismissed.

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

echo $notices['message'];

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?
 
Top Bottom