PHPackages                             myth/bay - 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. [Templating &amp; Views](/categories/templating)
4. /
5. myth/bay

Abandoned → [codeigniter4/CodeIgniter4](/?search=codeigniter4%2FCodeIgniter4)Library[Templating &amp; Views](/categories/templating)

myth/bay
========

Provides a simple mechanism for inserting view partials rendered in other classes. Can be used to provide a 'widgets' implementation or similar.

1.0-beta1(10y ago)66.6k↓33.3%4MITPHP

Since May 28Pushed 5y ago2 watchersCompare

[ Source](https://github.com/newmythmedia/bay)[ Packagist](https://packagist.org/packages/myth/bay)[ Docs](https://github.com/newmythmedia/bay)[ RSS](/packages/myth-bay/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

myth:Bay
========

[](#mythbay)

[![Build Status](https://camo.githubusercontent.com/feef93b92e74a0b0610491c876f21c29077d5b6e5cf6271929cbdede2101fd88/68747470733a2f2f7472617669732d63692e6f72672f6e65776d7974686d656469612f6261792e737667)](https://travis-ci.org/newmythmedia/bay)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b97840d138fdf3fa9cdde4b99f4f10dd5fd99ee3ddc7b85bcedd401477fffad3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e65776d7974686d656469612f6261792f6261646765732f7175616c6974792d73636f72652e706e673f623d646576656c6f70)](https://scrutinizer-ci.com/g/newmythmedia/bay/?branch=develop)

The Bay component provides a simple, framework-agnostic, way to include re-usable content in any `view` or rendered HTML, while keeping the logic in a separate class or module. This makes it simple to implement re-usable "widgets" in your applications, though that term is, perhaps, too grand.

A common example could be the "Recent Posts" section of a blog - the actual content is derived from the Blog module in a larger application, and appears in a number of places across your application, but you can easily insert it where you want it within the view layer, instead of loading it in every controller and sending it to the view.

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

[](#installation)

Installation is handled through [Composer](https://getcomposer.org/) as [myth/bay](#).

More information can be found in the [wiki](https://github.com/newmythmedia/bay/wiki)

General Usage
-------------

[](#general-usage)

Bays have only one real requirement: You must have a class that is either already loaded, or can be autoloaded, with a function that returns a string. There are a couple of finer points to consider, but that is the basics that are needed.

**For these examples, we will assume that we are creating a blog system, and the we want to show the recent posts as a Bay.**

To instantiate our Bay system, we simply create a new instance of `Myth\Bay\Bay`.

```
$bay = new Myth\Bay\Bay();

```

Then you just need to ensure that object is available within your view layer. For CodeIgniter, you would need to pass it as a variable to the `view()` command.

### Calling Without Parameters

[](#calling-without-parameters)

The simplest usage is to simply call a single method that doesn't need any parameters at all. This is done with the `display()` method.

First, though, we need a class and method that we can call. For our purpses, we assume that it can be autoloaded just fine.

```
class Posts {
	public function recentPosts()
	{
		$posts = $this->postModel->findLatest(5);
		return $this->view('recentPosts', ['posts' => $posts] );
	}
}

// In your view layer...
$bay->display("\Blog\Posts::recentPosts");

```

This will attempt to autoload and create an instance of the `\Blog\Posts` class, and call the `recentPosts` function. The `recentPosts` function grabs the latest 5 posts from the database, then renders out a view that formats it properly, returning the rendered HTML to the Bay.

### Calling With Parameters

[](#calling-with-parameters)

Parameters in Bays are handled as a string, and contain one or more key/value pairs. This string is then parsed into an array of key/value pairs, which is passed to the target class' method. This provides a simple way to simulate named parameters so that you can provide the parameters in any way that you want.

```
class Posts {
	public function recentPosts( array $params=[] )
	{
		$limit = ! empty($params['limit']) ? $params['limit'] : 5;
		$offset = ! empty($params['offset']) ? $params['offset'] : 0;

		$posts = $this->postModel->findLatest( $limit, $offset );
		return $this->view('recentPosts', ['posts' => $posts] );
	}
}

// In your view layer...
$bay->display("\Blog\Posts::recentPosts", "limit=5 offset=0");

```

The parameters can be separated by either spaces (as shown) or by commas, depending on your preferences. Alternatively, you can pass an array of key/value pairs as the second parameter and it will be used untouched.

```
$bay->display("\Blog\Posts::recentPosts", ['limit' => 5, 'offset' => 0] );

```

Custom Loaders
--------------

[](#custom-loaders)

Bay supports the use of custom loaders in case you need to implement one specifically for your framework. These are simple classes that are only resonsible for locating and loading the class into memory. It must implement the `Myth\Bay\LibraryFinderInterface` which only has a single method: `find( $class )`.

One has been provided for [CodeIgniter 3](http://codeigniter.com) that can be used as an example if needed.

To use a custom loader you would pass an instance in as the first parameter when instantiating the Bay class.

```
$bay = new Myth\Bay\Bay( new Myth\Bay\CI3Finder() );

```

Once loaded, this class will be used to locate a class when any other autoloading fails to locate it.

Caching Results
---------------

[](#caching-results)

Bays support caching the rendered output so that you never have to hit the original class (or even autoload it) for better performance in many cases. You tell it you want it to be cached by providing a little bit of extra information in the `display()` call.

The third (optional) parameter to the `display` method is the name the cache should be stored as. If this is not provided, one will be built for you based on the class name, the method name, and an md5 hash of the params array. The fourth parameter is the number of **minutes** the cache should be stored for.

```
$bay->display("\Blog\Posts::recentPosts", "limit=5 offset=0", 'some-cache-key', 15);

```

This example would cache the results under the key `some-cache-key` and store it for 15 minutes. After the 15 minutes is up, the cache would be built again, automatically. The default TTL time is 0 minutes. Be sure to check this behavior with your cach engine of choice.

### Providing A Cache Engine

[](#providing-a-cache-engine)

In order for Bays to work in a framework-agnostic manner, we require a framework-integration library for the cache, much like what is used for the custom class loader, above. These classes must extend `Myth\Bay\CacheInterface` and must implement two methods: `get($key)` and `set($key, $content, $ttl)`. A CodeIgniter 3 integration has been provided.

This integration class must be provided during class construction as the second parameter.

```
$bay = new Myth\Bay\Bay( null, new Myth\Bay\CI3Cache() );

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.8% 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4008d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/65f693f45781e767ed8557b776fd775309e7a262629892b99cf38462931e9b26?d=identicon)[lonnieezell](/maintainers/lonnieezell)

---

Top Contributors

[![lonnieezell](https://avatars.githubusercontent.com/u/51931?v=4)](https://github.com/lonnieezell "lonnieezell (24 commits)")[![kenjis](https://avatars.githubusercontent.com/u/87955?v=4)](https://github.com/kenjis "kenjis (3 commits)")[![sandor-palffy](https://avatars.githubusercontent.com/u/15702950?v=4)](https://github.com/sandor-palffy "sandor-palffy (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

viewcomponentCell

### Embed Badge

![Health badge](/badges/myth-bay/health.svg)

```
[![Health](https://phpackages.com/badges/myth-bay/health.svg)](https://phpackages.com/packages/myth-bay)
```

###  Alternatives

[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8208.4M87](/packages/eftec-bladeone)[laracasts/presenter

Simple view presenters

8643.4M46](/packages/laracasts-presenter)[jenssegers/blade

The standalone version of Laravel's Blade templating engine for use outside of Laravel.

8661.2M109](/packages/jenssegers-blade)[backpack/generators

Generate files for laravel projects

3122.6M18](/packages/backpack-generators)[laminas/laminas-view

Fast and type safe HTML templating library with a flexible plugin system supporting multistep template composition

7526.3M230](/packages/laminas-laminas-view)[friendsofcake/cakephp-csvview

A CSV View class for CakePHP

1762.5M3](/packages/friendsofcake-cakephp-csvview)

PHPackages © 2026

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