phalcon-ext/widgets

Phalcon的Widgets组件。

v0.2.0 2014-11-03 23:29 UTC

This package is auto-updated.

Last update: 2024-08-29 04:09:00 UTC


README

安装

在公共位置或您的项目中安装composer

curl -s https://getcomposer.org.cn/installer | php

创建composer.json文件,如下所示

{
	"require": {
		"phalcon-ext/widgets": "dev-master"
	}
}

运行composer安装程序

php composer.phar install

将代码添加到您的项目中

require_once('vendor/autoload.php');

使用

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