Open Source Content Management System

MgdSchema method connect

__void $object->connect(event_name, array callback, [array params])__

Minimum version: Midgard 1.9

Connects callback to event.

This method takes three arguments:

  • event_name, a name of the event for which callback is connected to, for example action_update_hook, action_created or action_loaded

  • callback, an array which is user defined PHP callback

  • params, an array with parameters which will be passed to callback

A callback function is connected to event(signal) emited by instance which invokes connect method. You may connect to one instance and event as many callbacks as you need.

<?php  

function my_callback($object, $data)
{
    echo "Connected to ".$object->guid;
    echo "And have special data ".$data;   
}

$article = midgard_object_class::factory("midgard_article", 123);
$article->connect("action_update_hook", array("my_callback"), array("abc"));

$article->update();

?>

Read more about events.

Designed by Nemein, hosted by Anykey