PHP code example of verbant / wn-livewire-plugin

1. Go to this page and download the library: Download verbant/wn-livewire-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

verbant / wn-livewire-plugin example snippets


    'component name' => ['LivewireClass' => Class of Livewire, 'ViewName' => 'name of view in components|controllers/component name', 'ViewPath' => "full path to this view"];

$this->renderLivewire("name", [optional arguments]); somewhere in a PHP markup-file.

public $count = 1;

public function add()
{
  $this->count++;
}

public function subtract()
{
  $this->count--;
}

 namespace YourNamespace\PluginName;

use YourNamespace\PluginName\Components\Lw;
use YourNamespace\PluginName\Components\Lw\Lw as LiveW;

class PluginName extends PluginBase
{
  public function registerComponents()
  {
    return [
      Lw::class => 'lw',
    ];
  }
  
  public function registerLivewireComponents()
  {
    return [
      'lw' => ['LivewireClass' => LiveW::class, 'ViewName' => 'default', 'ViewPath' => $this->getPluginPath() . '/components/lw'],
    ];
  }

  // other plugin code
}

 namespace YourNamespace\PluginName\Components;

use Cms\Classes\ComponentBase;

class Lw extends ComponentBase
{
  use \Verbant\Livewire\Traits\LivewireComponent;
  /**
   * Gets the details for the component
   */
  public function componentDetails()
  {
    return [
      'name'        => 'lw Component',
      'description' => 'No description provided yet...'
    ];
  }

  /**
   * Returns the properties provided by the component
   */
  public function defineProperties()
  {
    return [];
  }
}

public $count = 1;

public function add()
{
  $this->count++;
}

public function subtract()
{
  $this->count--;
}

 namespace YourNamespace\PluginName;

use System\Classes\PluginBase;
use YourNamespace\PluginName\Controllers\Lwc\Lwc as LiveWc;

class Plugin extends PluginBase
{
  public function registerLivewireComponents()
  {
    return [
      'lwc' => ['LivewireClass' => LiveWc::class, 'ViewName' => 'default', 'ViewPath' => $this->getPluginPath() . '/controllers/lwc'],
    ];
  }

  // other plugin code
}

 namespace YourNamespace\PluginName\Controllers;

use BackendMenu;
use Backend\Classes\Controller;

/**
 * Lw Controller Backend Controller
 */
class Lwc extends Controller
{
  use \Verbant\Livewire\Traits\LivewireController;
  /**
     * @var array Behaviors that are implemented by this controller.
     */
    // public $implement = [
    //     LivewireController::class
    // ];

    public function __construct()
    {
        parent::__construct();
        // possible setContext() and other code
    }
    
    public function index()
    {
    }
}

public $count = 1;

public function add()
{
  $this->count++;
}

public function subtract()
{
  $this->count--;
}

$this->renderLivewire("lwc", [optional value for the component]);