PHPackages                             yidas/codeigniter-widget - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. yidas/codeigniter-widget

ActiveLibrary

yidas/codeigniter-widget
========================

Developing

1.0.0(7y ago)43.1k↓100%8[1 PRs](https://github.com/yidas/codeigniter-widget/pulls)1MITPHPPHP &gt;=5.4.0

Since Sep 23Pushed 4y ago2 watchersCompare

[ Source](https://github.com/yidas/codeigniter-widget)[ Packagist](https://packagist.org/packages/yidas/codeigniter-widget)[ Docs](https://github.com/yidas/codeigniter-widget)[ RSS](/packages/yidas-codeigniter-widget/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (1)

 [ ![](https://camo.githubusercontent.com/5b8d9090a678d487fbff6d0d7400659c2180a80374753a34de65cc380c2e2dca/68747470733a2f2f636f646569676e697465722e636f6d2f6173736574732f696d616765732f63692d6c6f676f2d6269672e706e67) ](https://codeigniter.com/)

CodeIgniter Widget
==================

[](#codeigniter-widget)

CodeIgniter 3 Widget for reusable building view blocks

[![Latest Stable Version](https://camo.githubusercontent.com/f3126b60bfb21096d08cfa88e3b8366eef9c54e50d895f358dc78935dacb52de/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f636f646569676e697465722d7769646765742f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/codeigniter-widget)[![Latest Unstable Version](https://camo.githubusercontent.com/433bef1dfae9c9fde639670fd48034ee037d533eb80d5ff8c4b2720e0b8d45ab/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f636f646569676e697465722d7769646765742f762f756e737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/codeigniter-widget)[![License](https://camo.githubusercontent.com/4ef05cf88136289b048cc257e2afcc2f6914a9965a2253b598c3e14e311e2577/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f636f646569676e697465722d7769646765742f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/codeigniter-widget)

This Widget extension is collected into [yidas/codeigniter-pack](https://github.com/yidas/codeigniter-pack) which is a complete solution for Codeigniter framework.

Features
--------

[](#features)

- *Common interface with Yii2 pattern like*
- ***Reusable building blocks** implementation*
- ***PSR-4 Namespace** support for static call*

---

OUTLINE
-------

[](#outline)

- [Demonstration](#demonstration)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Create Widgets](#create-widgets)
    - [Rendering View](#rendering-view)
    - [Utilizing CodeIgniter Resources](#utilizing-codeigniter-resources)
- [Usage](#usage)
- [Reference](#reference)

---

DEMONSTRATION
-------------

[](#demonstration)

Define a widget then use it in Codeigniter's view:

```

 'Good morning']);?>

```

---

REQUIREMENTS
------------

[](#requirements)

This library requires the following:

- PHP 5.4.0+
- CodeIgniter 3.0.0+
- yidas/codeigniter-psr4-autoload 1.0.0+

---

INSTALLATION
------------

[](#installation)

Run Composer in your Codeigniter project under the folder `\application`:

```
composer require yidas/codeigniter-widget

```

Check Codeigniter `application/config/config.php`:

```
$config['composer_autoload'] = TRUE;
```

> You could customize the vendor path into `$config['composer_autoload']`

---

CONFIGURATION
-------------

[](#configuration)

Widget extension require [yidas/codeigniter-psr4-autoload](https://github.com/yidas/codeigniter-psr4-autoload) to implement PSR-4 Namespace, which you need to [configure](https://github.com/yidas/codeigniter-psr4-autoload#configuration) at first:

### 1. Enabling Hooks

[](#1-enabling-hooks)

The hooks feature can be globally enabled/disabled by setting the following item in the `application/config/config.php` file:

```
$config['enable_hooks'] = TRUE;
```

### 2. Adding a Hook

[](#2-adding-a-hook)

Hooks are defined in the `application/config/hooks.php` file, add above hook into it:

```
$hook['pre_system'][] = [new yidas\Psr4Autoload, 'register'];
```

After the configuration, you are able to create widgets.

---

CREATE WIDGETS
--------------

[](#create-widgets)

To create a widget, extend from `yidas\Widget` and override the `init()` and/or `run()` methods, remember to defind this widget a current namespace refering by [yidas/codeigniter-psr4-autoload](https://github.com/yidas/codeigniter-psr4-autoload).

`init()` contains the code that initializes the widget properties.

`run()` contains the code that generates the rendering result of the widget.

In the following example, `Hello` widget display the partial view with assigning to its `message` property. If the property is not set, it will display your Codeigniter `base_url` by default. This widget file should place in `application/widgets/Hello.php`:

```
