Search code examples
phpcodeigniterpyrocms

PyroCMS Execute code after stream has saved


So I've got a PyroCMS project that I'm working on that is a backend for a mobile app. What I'm trying to do is send push notifications when a certain stream gets a new entry.

From what I've read here, it looks like there is no way to tell when the form data is actually saved with cp->entry_form()

Anyone have any insight?


Solution

  • Events to the rescue!

    Check out the docs on events.

    Basically you'll have to create an events.php in your module (and maybe even create a small module with no functionality besides this) and register for the streams_post_insert_entry and streams_post_update_entry events.

    Example events.php:

    <?php defined('BASEPATH') or exit('No direct script access allowed');
    
    class Events_Yourmodule
    {
        protected $ci;
    
        public function __construct()
        {
            $this->ci =& get_instance();
    
            Events::register('streams_post_insert_entry', array($this, 'delete_cache'));
            Events::register('streams_post_update_entry', array($this, 'delete_cache'));     
        }
    
        public function delete_cache( $event )
        {
            // check if the event is for the stream we're interested in
            if($event['stream']->stream_slug != 'the-stream-im-interested-in')
              return;
    
            // now, do stuff... like delete cache
        }
    }