Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A starting point for extensions for the Yii PHP framework.
PHP
branch: master
Failed to load latest commit information.
behaviors Change to use composer autoload and refactor code
.gitignore Initial commit
LICENSE.txt
README.md Update README.md
composer.json Change to use composer autoload and refactor code

README.md

yii-extension

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');
Something went wrong with that request. Please try again.