CodeIgniter Forums
Event Triggering for Codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Event Triggering for Codeigniter (/thread-61036.html)



Event Triggering for Codeigniter - El Forum - 09-02-2014

[eluser]riwakawd[/eluser]
I would like to know if it is possible to use open cart events trigger and convert it with codeigniter

Because I would like to use it in one of my model functions. What would I need to do? I have my database cache set up.

If there is some thing similar to this all ready done with codeigniter please let me know cheers.

Model example

Code:
public function editStore($website_id, $data) {

$this->event->trigger('pre_admin_edit_store', $data);

some->query->code();

$this->cache->delete('website');

$this->event->trigger('admin_edit_store');

}

Events lib. // Not sure if will work from open cart to codeigniter lib.

Code:
class Events {

  public function trigger($event, &$data = array()) {
        if (!array_key_exists($event, $this->events)) {
            return true;
        }

        foreach ($this->events[$event] as $handler) {
            $parts = explode('/', $handler);

            $event = $this->load->event($parts[0] . '/' . $parts[1]);

            if (is_callable(array($event, $parts[2]))) {
                $event->{$parts[2]}($data);
            }
        }

        return true;
    }
}



Event Triggering for Codeigniter - El Forum - 09-03-2014

[eluser]InsiteFX[/eluser]
CodeIgniter Events Library:

Events Library