PHP code example of phalcon-ext / widgets

1. Go to this page and download the library: Download phalcon-ext/widgets 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/ */

    

phalcon-ext / widgets example snippets


class SomeWidget extends Phalcon\Ext\Widgets\WidgetBase
{
  public function init()
  {
    // optional some method
  }
  
  public function render($params = null) 
  {
    return $params['a'] + $params['b'] * ($params['c'] ?: 1);
  }
}

// Register widgets manager in DI
$di->setShared('widgets', function() use ($di) {

  $widgets = new Phalcon\Ext\Widgets\Manager();
  
  // Register some widget (the syntax is similar in DI)
  $widgets->set('some', function($options) {
    $widget = SomeWidget($options);
    $widget->init();
    
    return $widget;
  });
  
  return $widgets;
});


/**
 * Somewhere in view
 */

$options = []; // Optional parameter, It will be passed to the constructor of the widget before creating

echo $this->getDI()->get('widgets')->render('some', ['a' => 5, 'b' => 5, 'c' => 2], $options); // 15
bash
php composer.phar install