Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time

Code Samples


Subscribing to channels

    public function indexAction(Request $request, Radio $radio)
        // Presence and Private channels need excplicit configuration, see config.yml 
            ->getPresenceChannel("user", ["id" => $this->getUser()->getId()])

        // Public channels can be created without any configuration
        // Channel type will be resolve by config type, if several channel with the same name exist 
        // the priority is as follows: presence -> private -> public

Publishing events

    public function publishToPublicChannel(Request $request, Radio $radio)
        $global = $radio->getPublicChannel("global");
        $child_1 = $radio->getPublicChannel("global.child_1");    // the dot indicates channel inheritence
        $child_1 = $radio->getPublicChannel("global.child_2");

        $child_1->publish(new Message("Hello Child Channel 1!")); // published to 'global' and 'global.child_1'
        $child_2->publish(new Message("Hello Child Channel 2!")); // published to 'global' and 'global.child_2'

        return new Response("Done.");

    public function publishToPresenceChannel(Request $request, Radio $radio)
        $channel = $radio->getPresenceChannel("user", ["id" => $this->getUser()->getId()]);
        $channel->publish(new Message("Hello Presence Channel!"));

        return new Response("Done.");
     public function publishNotifications(Request $request, Radio $radio)
        $notificationChannel = $radio->getPrivateChannel("user_notifications", ["id" => 9999]);

        $element = \Pimcore\Model\DataObject\MyEntity::getById(12345);
            ->publish(new Notification("Yeay!", "Lorem ipsum dolor sit amet!"))
            ->publish(new Notification("Wow!", "Lorem ipsum dolor sit amet!", $element)

Fetching unread notifications

    public function notificationsAction(Request $request){
        $notifications = new Listing();
        $notifications->addConditionParam("`read` IS NULL");
        $notifications->addConditionParam("`targetUser` = ?", $this->getUser()->getId());
        $this->view->notifications = $notifications;


For details concerning the client side javascript have a look at the pusher client api guide. If you use $myChannel->subscribe() on the server-side as described the initialization and subscriptions take place automatically as long as you use the ignite template helper as described below.

    var Ignite = Ignite || {};
    /* output the script for establishing websocket connection and subscriptions/unsubscriptions */
    <?= $this->ignite() ?>'message', function (data) {
        // handle event

    Ignite.channels.user.bind('message', function (data) {
        // handle event
    Ignite.channels.user.bind('pusher:member_added', function (member) {
        // handle presence channel user event
    Ignite.channels.notifications.bind('notification', function (data) {
        // handle event