Debugging with Ray

Nitro is no longer supported. Please see our announcement and DDEV migration guide.

Ray (opens new window) is a desktop PHP debugging tool that makes it easy to debug Craft or any PHP application.

# Installation

Ray’s first-party Craft plugin (opens new window) makes configuration quick and easy. From your terminal, require and install it:

nitro composer require spatie/craft-ray
nitro craft plugin/install craft-ray

If you only want to use Ray in development, run
nitro composer require spatie/craft-ray --dev

# Configuring

In the control panel, visit SettingsPlugins, choose Ray and switch on the Enable setting.

Enter the following:

Host: host.docker.internal
Remote Path: /app
Local Path: /path/to/your/local/project

tutorial.nitro/admin/settings/plugins/craft-ray
Screenshot of Ray plugin settings in the Craft control panel
Ray plugin settings

# Usage

You can use Ray directly in your Twig templates or Plugin. To use Ray in Twig, open your template of choice and enter the following:

{{ ray("Hello Ray!") }}

For a full site of available methods in Twig, visit the Ray documentation for Craft CMS (opens new window).

The Ray desktop app will now have a new debug event!

Ray App

To use Ray for plugin or module development, enter the following in your plugin:

<?php

namespace modules;

use Craft;

class Module extends \yii\base\Module
{
    public function init()
    {
        Craft::setAlias('@modules', __DIR__);

        if (Craft::$app->getRequest()->getIsConsoleRequest()) {
            $this->controllerNamespace = 'modules\\console\\controllers';
        } else {
            $this->controllerNamespace = 'modules\\controllers';
        }

        ray('Hello Ray!');

        ray()->showEvents();

        parent::init();

        // Custom initialization code goes here...
    }
}

For a complete list of available methods, see the Yii2 documentation (opens new window) for more detailed usage examples.