crisu83/yii-extension

Tools for building extensions for the Yii PHP framework.

Installs: 2 944

Dependents: 4

Suggesters: 0

Security: 0

Stars: 3

Watchers: 1

Forks: 0

Type:yii-extension

1.2.0 2014-02-11 21:17 UTC

This package is auto-updated.

Last update: 2024-10-29 04:09:17 UTC


README

Latest Stable Version

A convenient way to start building your own extensions for the Yii PHP framework.

This project was created to minimize boilerplate code required when creating new extensions for Yii. It includes separate behaviors for Widgets, Components and Modules that all extend the ExtensionBehavior class.

Usage

Widgets

Attaching the behavior

Yii::import('vendor.crisu83.yii-extension.behaviors.*');

MyWidget extends CWidget
{
  public function init() 
  {
    parent::init();
    $this->attachBehavior('ext', new WidgetBehavior);
  }
}

Registering assets

$this->publishAssets(__DIR__ . '/path/to/assets');
$this->registerCssFile('css/styles.css');
$this->registerScriptFile('js/script.js');

Components

Attaching the behavior

Yii::import('vendor.crisu83.yii-extension.behaviors.*');

MyApplicationComponent extends CApplicationComponent
{
  public function init() 
  {
    parent::init();
    $this->attachBehavior('ext', new ComponentBehavior);
  }
}

Importing classes and directories

$this->createPathAlias('myExtension', __DIR__);
$this->import('MyClass');
$myClass = new MyClass;

Registering assets

$this->publishAssets(__DIR__ . '/path/to/assets');
$this->registerCssFile('css/styles.css');
$this->registerScriptFile('js/script.js');

Modules

Attaching the behavior

Yii::import('vendor.crisu83.yii-extension.behaviors.*');

MyModule extends CWebModule
{
  public function init() 
  {
    parent::init();
    $this->attachBehavior('ext', new ModuleBehavior);
  }
}

Importing classes and directories

$this->import('MyClass');
$myClass = new MyClass;

Registering assets

$this->publishAssets(__DIR__ . '/path/to/assets');
$this->registerCssFile('css/styles.css');
$this->registerScriptFile('js/script.js');