PHPackages                             cwbit/cakephp-bootstrap-suite - 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. cwbit/cakephp-bootstrap-suite

ActiveCakephp-plugin[Templating &amp; Views](/categories/templating)

cwbit/cakephp-bootstrap-suite
=============================

A CakePHP plugin for the Bootstrap CSS and JS framework

115[7 issues](https://github.com/cwbit/cakephp-bootstrap-suite/issues)PHP

Since Oct 16Pushed 11y ago1 watchersCompare

[ Source](https://github.com/cwbit/cakephp-bootstrap-suite)[ Packagist](https://packagist.org/packages/cwbit/cakephp-bootstrap-suite)[ RSS](/packages/cwbit-cakephp-bootstrap-suite/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

readme.md

cakephp-bootstrap-suite
=======================

[](#cakephp-bootstrap-suite)

=======================

The CakePHP Bootstrap Suite (Bootstrap) is a plugin suite of CakePHP Helpers that attempt to make using the Bootstrap CSS and JS framework with CakePHP a lot easier.

It does this by providing helper classes that employ an Entity, Collection, and Wrapped Collection architecture to create and manipulate objects.

NOTE: Technically you can use the Entity architecture of this plugin to print out ANY valid HTML, XML and even preconfigure them with default, overrideable options. Want an entity that can handle perfectly formatted reponsive image tags? If you've typed more than 3 lines (from class to } ) then you've type too much. Want an infinitely expandable, perfectly formatted, bootstrap styled, manipulatable and on-the-fly modifiable unordered list collection? You should clock in at about ... 7 lines total code. 2 lines of which are class declarations and 2 lines of which are the close curly bracket for your class.

Let's create a complete, fully functional example in 7 lines or less.

```
	//.. in app/Plugins/Bootstrap/View/Helper/ListCollectionHelper.php

	class ListCollectionHelper extends BootstrapHelperWrappedEntityCollection{
		public $_options = ['tag'=>'ul','baseClass'=>'list-group'];
		public $_entityClass = 'ListItem';
	}
	class ListItem extends BootstrapHelperEntity{
		public $_options = ['tag'=>'ul','baseClass'=>'list-group-item'];
	}
```

YUP. 7 lines. Wanna use it? Let's add it as a helper and start using it

```
	//.. in your controller
	public $uses = ['Bootstrap.ListCollection'];

	//.. in your view
	$l = $this->ListCollection->add();
	$l->add('Hello');
	$l->add('World');
```

Ok, how about we see what it looks like when told to print itself.

```
	# anything that calls __toString() will work
	echo $l;

	# prints out the following

		Hello
		World

```

Perfectly formatting, classed and le sexy. Mindblown.

We (figuratively) just created a UL helper in 7 lines that oh, I dunno, is also a perfectly formatted, expandable, go-back-and-change-something-on-the-fly-if-you-want Bootstrap List Group.

To put it another way, this is an extremely powerful presentation system that just happens to come pre-bundled with Helpers that support Bootstrap.

Requirements
------------

[](#requirements)

===

- CakePHP
- Bootstrap 3.x Technically you can support whatever version of bootstrap you want, just make/modify the appropriate helpers.

TOC
---

[](#toc)

====

- [Architecture](#arch)
- [Using the Plugin](#how)
- [Glyphicon Example](#how-ex-1)
- [Table Example](#how-ex-2)
- [Create your Own](#create)
- [Entity](#create-entity)
- [Entity Collection](#create-entity-collection)
- [Wrapped Entity Collection](#create-entity-wrapped-collection)
- [Exceptions](#exceptions)
- [Plugin Installation](#installation)

\## A note about the Architecture ==== This plugin uses Entities to control and display everything. Each Entity is an intelligent class that holds all of its parts until it needs to spit everything out. Please note: the entity concept was devised quite separately from what is apparently coming in Cake3 for models, so any similarity is not intentional and does not imply a similar usage or implementation.

\## How to use the Plugin ==== Make sure you install it following the instructions later in this readme. There are a number of Helper Classes already provided. If you know what a Test Case is you should check out the Test cases already provided to see examples of how each helper is used.

\### Glyphicon example (easy) === Let's take a look at the pretty simple Glypicon helper ```php ```
class ExamplesController extends AppController{
	public $uses = ['Bootstrap.BootstrapGlyphicon'];

	public function view(){}
}

//..view.ctp

echo $this->BootstrapGlyphicon->create('minus');

#will print out

```

```

That's it - that's how you use the GlyphiconHelper! Easy, eh?

### Table Example (more complicated)
===
Now let's look at a more complicated example, because this is where the setup will really start to shine.

```php

	class ExamplesController extends AppController{
		public $uses = ['Bootstrap.BootstrapTable'];

		public function view(){
			$this->set('examples', $this->Example->find('all'));
		}
	}

	#../view.ctp

	$t = $this->BootstrapTable->add();

	$t->Header->add()->addMultiple(['Name'],['Description']);
	foreach($examples as $example):
		$t->Body->add()->addMultiple(
				[$example['name']],
				[$example['description']],
			);
	endforeach;

	#print it out
	echo $t;

	#will give us

				Name
				Description

				Example One
				Description One

				Example Two
				Description Two

				Example Three
				Description Three

```

Not bad! See how it provided default Bootstrap formatting, wrapped all your data in the proper elements, and still only required a few calls?

That's a pretty basic example. There are lots more things you can do, even with tables. But that should give you the gist of what's going on in each Helper.

Remember to take a look in the classes, the test cases provided, and any other examples (even the ones later in this doc) to figure out what's going on.

\## Creating your own Helper (or understanding what's going on) ==== The whole system uses three main peices. An Entity (something like a list item), and either a plain Entity Collection (to hold the list items) or a Wrapped Entity Collection (to hold the list items and wrap them in a `` when it prints itself.) or any and all combinations of all three.

If you're looking for a good example of a completx setup, check out the BootstrapTableHelper - it has all three!

We take a look at each of those three and how/why/when to build your own.

\### An example ENTITY An entity is, and should be, a single idea - A paragraph is an entity, a cell in a table is an entity, an image is an entity, etc. An entity can also be made up of other entities. Some entities are special collections of other entities, we will look at those in the next section. For our example we will make a completely useless Paragraph entity. A Paragraph entity, for example, would know that it uses the `` tag, that it has a `class` of `foo` and that in between its tags is the content `Hello World!`. When anything attempts to get the string representation of it the Paragraph entity will convert itself into a full-formed paragraph that looks like this

```

	#example class configuration
	class ParagraphEntity extends BootstrapHelperEntity{
		protected $_options = ['tag'=>'p'];
	}

	#example Paragraph creation with optional configuration
	$p = $this->ParagraphEntity->create('Hello World', ['htmlAttributes' => ['class' => 'foo']])

	#any of the following will produce...
	echo $p;
	echo $p->toString();
	echo (string) $p;

	#... this output
	Hello World!
```

\### Continuing the Example with an ENTITY COLLECTION An EntityCollection is simply that, a collection of entities with no special relation to each other. Most of the Helpers in this plugin are Entity Collections; for example `GlyphiconHelper` extends `BootstrapHelperEntityCollection` and simply holds any glyphs you create in case you need to get to them later on.

There is a special case for Wrapped Entity Collections that we will look at in the next section.

Continuing on with our Paragraph entity, let's make the following adjustments. Let's make a paragraph collection that stores all the paragraphs we add.

```
	#create a collection class that will use the ParagraphEntity class (from prev example) when it create()s new entities
	class ParagraphCollection extends BootstrapHelperEntityCollection{
		public $_entityClass = 'ParagraphEntity';
	}

	#now let's use it (and yes, it was that easy)
	$this->ParagraphCollection->add('I');		# calling add() will instantiate an $_entityClass
	$this->ParagraphCollection->add('LOVE');	# call create(...params...) on the new instance
	$this->ParagraphCollection->add('ME');		# and set up some other collection-specific stuff
	$this->ParagraphCollection->addMultiple(	# you can also use addMultiple
		['LOTS'], 								# to call add multiple times
		['OF'], 								# by passing it an array of args for the add() function
		['PARAGRAPHS', ['htmlAttributes'=>['class'=>'serious']] ]
		);

	# we can do lots of other stuff with the collection, but let's just print it out for now
	echo $this->ParagraphCollection;

	# will produce the following
	I
	LOVE
	ME
	LOTS
	OF
	PARAGRAPHS
```

\### Continuing the example with a Wrapped Entity Collection Next we'll take a look at the special case of a Wrapped Entity Collection. Oddly enough, this class was what actually drove me to implement the entity architecture of the plugin.

It is often the case that you have an arbitrary number of items (1 or more) that all need to go together AND need to be wrapped in something else. The previous design required that you call a `begin() ... all your elements... end()` - cumbersome and iffy.

```

	#example of the old way
	echo $this->Nav->begin()
		echo $this->Nav->groupBegin();
			echo //...lots of nav elements...//
		echo $this->Nav->groupEnd();
	echo $this->Nav->end()
```

This old was was very cumbersome and required you to not only keep track of where you were, but more importantly, required you to intimately know the details of how each Helper worked, what groups needed to be called when, and what items could (or had to) go in what groups. It was a pain in the butt.

Thus wrapped entity collections were actually the drivers for the whole re-write.

Let's take a look.

Let's change our example from before to make a little more sense. Instead of dealing with Paragraphs lets create a `ListGroupHelper`. We'll use it to make a properly formatted Bootstrap List Group

```
	#first, lets make a list item entity
	class ListEntity extends BootstrapHelperEntity{
		public $_options = [					# bootstrap list items are just
			'tag' => 'li',						# 's
			'htmlAttributes' => [				# with a specific html class of
				'class' => 'list-group-item',   # 'list-group-item'
			]									# That's it! EASYMODE
		];										# The parent class will handle
	}											#   the rest

	#next, we'll make a wrapped entity collection
	class ListEntityCollection extends BootstrapHelperWrappedEntityCollection{
		public $_options = [			# The wrapped collection, unlike the
			'tag' => 'ul',				# regular collection, can actually take
			'htmlAttributes' => [		# formatting options.
				'class' => 'list-group'	# we'll see how they're used in a sec
			]
		]
	}

	#Let's get our ListGroup object
	#this call won't work if you copy/paste this example, you'll need
	#to set up $view and $settings first
	#this is more to show you what Cake is normally passing your Helper
	$listGroup = new ListEntityCollection($View, $settings);

	#Now let's add some list items (like we saw earlier)
	$listGroup->add('Cras justo odio');
	$listGroup->add('Dapibus ac facilisis in');
	$listGroup->addMultiple(
		['Morbi leo risus'],
		['Porta ac consectetur ac'],
		['Vestibulum at eros']
		);

	#now let's see why we bothered with a wrapped collection
	echo $listGroup;

	#if we echo the collection we will get the following!

	  Cras justo odio
	  Dapibus ac facilisis in
	  Morbi leo risus
	  Porta ac consectetur ac
	  Vestibulum at eros

```

See how it wrapped all the list items for us? No need for us to remember how they're supposed to go - it does that all for us!

WIN.

\## Exceptions ==== There are a couple of classes that don't follow the Entity architecture yet. NavHelper is a big one. In order to get some of them to work there are peices of the architecture that need to be designed first (like pass-through entities) and I haven't figured out the best way to do them yet. So, for now, some Helpers follow a slightly older, entity-less pattern. It's actually interesting to compare them to see how much work the newer design does automatically for you. Compare NavHelper and TableHelper - both do about the same amount of complexity/work, but one is vastly easier to read and maintain than the other.

\## Installation ==== *\[Using [Composer](http://getcomposer.org/)\]*

Add the plugin to your project's `composer.json` - something like this:

```
{
	"require": {
		"cwbit/cakephp-bootstrap-suite": "dev-master"
	}
}

```

Because this plugin has the type `cakephp-plugin` set in it's own `composer.json` composer knows to install it inside your `/Plugins` directory (rather than in the usual 'Vendor' folder). It is recommended that you add `/Plugins/Bootstrap` to your cake app's .gitignore file. (Why? [read this](http://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md).)

*\[Manual\]*

- Download and unzip the repo (see the download button somewhere on this git page)
- Copy the resulting folder into `app/Plugin`
- Rename the folder you just copied to `Bootstrap`

*\[GIT Submodule\]*

In your `app` directory type:

```
git submodule add -b master git://github.com/cwbit/cakephp-bootstrap-suite.git Plugin/Bootstrap
git submodule init
git submodule update

```

*\[GIT Clone\]*

In your `app/Plugin` directory type:

```
git clone -b master git://github.com/cwbit/cakephp-bootstrap-suite.git Bootstrap

```

### Enable plugin

[](#enable-plugin)

In 2.0 you need to enable the plugin your `app/Config/bootstrap.php` file:

```
    CakePlugin::load('Bootstrap');
```

If you are already using `CakePlugin::loadAll();`, then this is not necessary.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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/474fb8a03f077a57b5421dcc5b93a8c30f16e0ecbf0f17a239e46a0ebd8ab5f7?d=identicon)[cwbit](/maintainers/cwbit)

---

Top Contributors

[![cwbit](https://avatars.githubusercontent.com/u/6501207?v=4)](https://github.com/cwbit "cwbit (44 commits)")

### Embed Badge

![Health badge](/badges/cwbit-cakephp-bootstrap-suite/health.svg)

```
[![Health](https://phpackages.com/badges/cwbit-cakephp-bootstrap-suite/health.svg)](https://phpackages.com/packages/cwbit-cakephp-bootstrap-suite)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

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