Golden field A juvenile event book Hong Kong Kowloon Treasure Homicide Minor5 Incident

Source: Internet
Author: User
Events Event 5.1

The minor Event class provides a simple observer implementation that allows you to subscribe and listen to events in your application.

5.1.1 Subscribing to Events

First create an event class:

 
  Phpnamespace app\event;  Use minor\event\event; class extends event{    private$name;      Public function __construct ($name)    {        $this$name;    }      Public function setName ($name)    {        $this$name;    }     publicfunction  getName ()    {        return$this- >name;}    }

Then register this event in the configuration file:

 
  PHPreturn$events = [    ' app\event\demoevent '            = [' App\ Listener\demolistener ' = ' handle ',    ],;

5.1.2 Triggering events

Minor provides an event management class: Minor\event\eventmanger, which can trigger this event by invoking the static method Fire:eventmanager::fire ($event) of the class, for example:

class extends controller{    publicfunction Bar ($productName)    {         $eventnew demoevent (' demoevent ');        EventManager:: Fire ($event);         ...     }}

5.2 Listeners

The event manager EventManager will trigger the listener's development method through the configuration file when the event is triggered. In the 5.1.1 configuration file we configured the Demoevent listener as the App\listener\demolistener handle method, you can see the implementation of this class:

 
  Phpnamespace App\listener;  Use app\event\demoevent;  Use Minor\event\listener; class extends listener{    publicfunction$event)    {        Echo  $event->getname (). success!

'; }}

The above describes the Golden field a juvenile event book Hong Kong Kowloon Treasure Murder incident Minor5 incident, including the Golden field A juvenile event book Hong Kong Kowloon Treasure Murder Incident content, I hope to be interested in PHP tutorial friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.