PHPackages                             flaviovs/yii2-jsdata - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. flaviovs/yii2-jsdata

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

flaviovs/yii2-jsdata
====================

Pass data from a Yii 2.0 application to client JavaScript

05PHP

Since Nov 13Pushed 7y ago1 watchersCompare

[ Source](https://github.com/flaviovs/yii2-jsdata)[ Packagist](https://packagist.org/packages/flaviovs/yii2-jsdata)[ RSS](/packages/flaviovs-yii2-jsdata/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

yii2-jsdata
===========

[](#yii2-jsdata)

This package provides a framework for passing data from Yii 2.0 applications to Javascript.

Installation
------------

[](#installation)

```
$ composer require flaviovs/yii2-jsdata

```

Setup
-----

[](#setup)

**Step 1** -- Setup **yii2-jsdata** as a standard Yii2 component in your web app configuration:

```
[
	'components' => [
		'jsdata' => [
			'class' => \fv\yii\jsdata\Component::class,
		],
	]
]
```

**Step 2** -- Bootstrap the component in the web app:

```
[
	'bootstrap' => ['jsdata'],
]
```

Usage
-----

[](#usage)

Use the `data` attribute in the `jsdata` component to pass data from PHP to Javascript. Use the `appData` object in Javascript to get the data. Examples:

```
// Pass a simple value to Javascript (this goes in a controller or view.)
\Yii::$app->jsdata->data['message'] = 'Hello World!';
```

```
// Now access the data in Javascript.
alert(window.appData.message);
```

Notice that you can pass any values or data structure that can be converted from PHP to Javascript. You can also use [yii\\web\\JsExpression](http://www.yiiframework.com/doc-2.0/yii-web-jsexpression.html) to pass complex Javascript expressions:

```
// Pass a simple value to Javascript (this goes in a controller or view.)
\Yii::$app->jsdata->data['now'] = new \yii\web\JsExpression('new Date()');
```

**Note**: Usually Javascript data is initialized *before* any other script is run in the page. That means that you cannot use expressions that depends on other scripts (for example, jQuery).

Options
-------

[](#options)

The `jsdata` component accepts the following options:

- `varName` -- the name of the global Javascript data variable. Default "appData".
- `encodeOptions` -- Javascript encoding options. See  for all available constants. **Note**: for security reasons, `JSON_UNESCAPED_UNICODE` and `JSON_UNESCAPED_SLASHES` are always removed.

Issues
------

[](#issues)

Visit:

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c4f7729440b3a6349f7aaed372ad81ac4746b1c5b801abd644158daad410926e?d=identicon)[flaviovs](/maintainers/flaviovs)

---

Top Contributors

[![flaviovs](https://avatars.githubusercontent.com/u/1832699?v=4)](https://github.com/flaviovs "flaviovs (2 commits)")

### Embed Badge

![Health badge](/badges/flaviovs-yii2-jsdata/health.svg)

```
[![Health](https://phpackages.com/badges/flaviovs-yii2-jsdata/health.svg)](https://phpackages.com/packages/flaviovs-yii2-jsdata)
```

###  Alternatives

[spatie/statamic-health

Check the health of your Statamic app

115.3k](/packages/spatie-statamic-health)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
