{"id":15277417,"url":"https://github.com/yidas/codeigniter-widget","last_synced_at":"2025-04-12T14:52:08.279Z","repository":{"id":57086786,"uuid":"115614285","full_name":"yidas/codeigniter-widget","owner":"yidas","description":"CodeIgniter 3 Widget for reusable building view blocks","archived":false,"fork":false,"pushed_at":"2021-10-17T16:09:19.000Z","size":23,"stargazers_count":4,"open_issues_count":1,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T09:21:40.647Z","etag":null,"topics":["codeigniter3","mvc","view-block","view-model","widget"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yidas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-28T10:53:49.000Z","updated_at":"2022-01-26T07:06:47.000Z","dependencies_parsed_at":"2022-08-25T00:50:46.724Z","dependency_job_id":null,"html_url":"https://github.com/yidas/codeigniter-widget","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fcodeigniter-widget","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fcodeigniter-widget/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fcodeigniter-widget/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fcodeigniter-widget/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yidas","download_url":"https://codeload.github.com/yidas/codeigniter-widget/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586252,"owners_count":21128995,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codeigniter3","mvc","view-block","view-model","widget"],"created_at":"2024-09-30T11:06:05.677Z","updated_at":"2025-04-12T14:52:08.254Z","avatar_url":"https://github.com/yidas.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://codeigniter.com/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://codeigniter.com/assets/images/ci-logo-big.png\" height=\"100px\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eCodeIgniter Widget\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\nCodeIgniter 3 Widget for reusable building view blocks\n\n[![Latest Stable Version](https://poser.pugx.org/yidas/codeigniter-widget/v/stable?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-widget)\n[![Latest Unstable Version](https://poser.pugx.org/yidas/codeigniter-widget/v/unstable?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-widget)\n[![License](https://poser.pugx.org/yidas/codeigniter-widget/license?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-widget)\n\nThis Widget extension is collected into [yidas/codeigniter-pack](https://github.com/yidas/codeigniter-pack) which is a complete solution for Codeigniter framework.\n\nFeatures\n--------\n\n- *Common interface with Yii2 pattern like*\n\n- ***Reusable building blocks** implementation*\n\n- ***PSR-4 Namespace** support for static call* \n\n---\n\nOUTLINE\n-------\n\n- [Demonstration](#demonstration)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [Create Widgets](#create-widgets)\n  - [Rendering View](#rendering-view)\n  - [Utilizing CodeIgniter Resources](#utilizing-codeigniter-resources)\n- [Usage](#usage)\n- [Reference](#reference)\n\n---\n\nDEMONSTRATION\n-------------\n\nDefine a widget then use it in Codeigniter's view:\n\n```html\n\u003c?php\nuse app\\widgets\\Hello;\n?\u003e\n\u003cdiv\u003e\n\u003c?=Hello::widget(['message' =\u003e 'Good morning']);?\u003e\n\u003c/div\u003e\n```\n\n---\n\nREQUIREMENTS\n------------\nThis library requires the following:\n\n- PHP 5.4.0+\n- CodeIgniter 3.0.0+\n- yidas/codeigniter-psr4-autoload 1.0.0+\n\n---\n\nINSTALLATION\n------------\n\nRun Composer in your Codeigniter project under the folder `\\application`:\n\n    composer require yidas/codeigniter-widget\n    \nCheck Codeigniter `application/config/config.php`:\n\n```php\n$config['composer_autoload'] = TRUE;\n```\n    \n\u003e You could customize the vendor path into `$config['composer_autoload']`\n\n---\n\nCONFIGURATION\n-------------\n\nWidget 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:\n\n\n### 1. Enabling Hooks\n\nThe hooks feature can be globally enabled/disabled by setting the following item in the `application/config/config.php` file:\n\n```php\n$config['enable_hooks'] = TRUE;\n```\n\n### 2. Adding a Hook\n\nHooks are defined in the `application/config/hooks.php` file, add above hook into it:\n\n```php\n$hook['pre_system'][] = [new yidas\\Psr4Autoload, 'register'];\n```\n\nAfter the configuration, you are able to create widgets.\n\n---\n\nCREATE WIDGETS\n--------------\n\nTo 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).\n\n\n`init()` contains the code that initializes the widget properties.\n\n`run()` contains the code that generates the rendering result of the widget.\n\nIn 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`:\n\n```php\n\u003c?php\n\nnamespace app\\widgets;\n\nuse yidas\\Widget;\n\nclass Test extends Widget\n{\n    // Customized variable for Widget\n    public $message;\n    \n    public function init()\n    {\n        // Use $this-\u003eCI for accessing Codeigniter object\n        $baseUrl = $this-\u003eCI-\u003econfig-\u003eitem('base_url');\n        \n        if ($this-\u003emessage === null) {\n            $this-\u003emessage = \"Your Site: {$baseUrl}\";\n        }\n    }\n    \n    public function run()\n    {\n        // Render the view `test.php` in `WidgetPath/views` directory,\n        return $this-\u003erender('test', [\n            'message' =\u003e $this-\u003emessage,\n            ]);\n    }\n}\n```\n\n\u003e [yidas/codeigniter-psr4-autoload](https://github.com/yidas/codeigniter-psr4-autoload) provides the PSR-4 Namespace ability for Codeigniter framework.\n\n### Rendering View\n\n```php\npublic string render(string $view, array $variables=[])\n```\n\nBy default, views for a widget should be stored in files in the `WidgetPath/views` directory, where WidgetPath stands for the directory containing the widget class file. \n\nTherefore, the above example will render the view file `app/widgets/views/hello.php`, assuming the widget class is located under `app/widgets`. \n\nYou may override the `yidas\\Widget::getViewPath()` method to customize the directory containing the widget view files.\n\n*Example:*\n\n```php\n    public function run()\n    {\n        return $this-\u003erender('view_name', [\n            'variable' =\u003e $this-\u003eproperty,\n            ]);\n    }\n```\n\n\n### Utilizing CodeIgniter Resources \n\nWidget already prepared `$CI` property which is CodeIgniter Resources object, you could access it by `$this-\u003eCI` in your widget's `init()` or `run()` methods.\n\n```php\n    public function run()\n    {\n        // Get data from a model\n        $this-\u003eCI-\u003eload-\u003emodel('Menu_model');\n        $list = $this-\u003eCI-\u003eMenu_model-\u003egetList();\n        \n        // Build widget's view with list data\n        return $this-\u003erender('test', [\n            'list' =\u003e $list,\n            ]);\n    }\n```\n\n---\n\nUSAGE\n-----\n\n### Widget on View\n\nStatically call `widget()` with config in view, and the widget would render into that place:\n\n```html\n\u003c?php\nuse app\\widgets\\Hello;\n?\u003e\n\u003cdiv\u003e\n\u003c?=Hello::widget(['message' =\u003e 'Good morning']);?\u003e\n\u003c/div\u003e\n```\n\n---\n\nREFERENCE\n---------\n\n- [Application Structure: Widgets | The Definitive Guide to Yii 2.0 | Yii PHP Framework](https://www.yiiframework.com/doc/guide/2.0/en/structure-widgets)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyidas%2Fcodeigniter-widget","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyidas%2Fcodeigniter-widget","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyidas%2Fcodeigniter-widget/lists"}