2017 © Pedro Peláez
 

cakephp-plugin viewbits

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

image

davidyell/viewbits

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

  • Thursday, March 17, 2016
  • by davidyell
  • Repository
  • 1 Watchers
  • 2 Stars
  • 276 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 1 % Grown

The README.md

ViewBits Component

Why?

I needed a way to allow certain blocks of content in a view to be content managed without affecting the layout., (*1)

What it does

It will hook beforeRender() to match a route in order to load the View Bits that you need for that route. So that you can include them in your views., (*2)

Compatability

Compatible with CakePHP 2.x. (Developed on 2.2.3), (*3)

Installation

  • Download and unzip into app/Plugins/ViewBits
  • $ git clone https://github.com/davidyell/CakePHP-ViewBits.git app/Plugin/ViewBits
  • $ git submodule add https://github.com/davidyell/CakePHP-ViewBits.git app/Plugin/ViewBits

Setup

First you will need to create the database table to store your View Bits., (*4)

Import the view_bits.sql file from app/Plugin/ViewBits/Config/Schema/view_bits.sql
OR
You can use CakeDC/migrations to run the migration file.
cake Migrations.migration run --plugin ViewBits, (*5)

Then you'll want to enable the plugin in your app/Config/bootstrap.php with CakePlugin::load('ViewBits'). If you are already using CakePlugin::loadAll() then you don't have to worry., (*6)

To enable the component it will need to be included in your controllers $components array. I'd suggest adding it to your AppController.php, (*7)

class AppController extends Controller {
    public $components = array('ViewBits.ViewBits');
}

Usage

The component will match based on the routes in the url. So if you add a View Bit with a route of / it will be loaded on your root or home page. If you add one with a route of /pages/display/about it will show up on your about page.
Wild cards are also supported in the routing using *. If you add a route of * the ViewBit will be loaded on all pages. You can combo them up such as /users/* which will load on all the UsersController routes., (*8)

In order to display your View Bits, you'll need to include the plugin helper which outputs the content. In your controller you must add the helper to your helpers array., (*9)

public $helpers = array('ViewBits.ViewBits');

Example, (*10)

<?php echo $this->ViewBits->out($viewbits, 1);?>
// $viewbits is an array of items generated by the component
// 1 is the item you want to output

What you have to do

You'll need to customise the admin interface and deal with hooking it into your current admin. The admin views are based on my NiceAdmin plugin., (*11)

Todo

v0.1 Milestone

  • ~~Create a helper to replace the element~~
  • ~~Come up with a better way to manage multiple View Bits in the new Helper~~
  • ~~Ordering so that bits are loaded in the page order~~
  • ~~Enhance the route matching to take regex, wildcards or similar~~
  • ~~Validate the routes to make sure they exist~~
  • ~~Custom validation function to lookup routes and make sure they exist~~
  • ~~Setup for Composer and add to Packigist~~

License

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License., (*12)

The Versions

17/03 2016

dev-master

9999999-dev

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

  Sources   Download

The Requires

 

17/03 2016

0.1.11

0.1.11.0

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

  Sources   Download

The Requires

 

17/03 2016

0.1.10

0.1.10.0

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

  Sources   Download

The Requires

 

01/09 2015

0.1.9

0.1.9.0

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

  Sources   Download

The Requires

 

26/08 2015

0.1.8

0.1.8.0

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

  Sources   Download

The Requires

 

09/06 2015

0.1.7

0.1.7.0

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

  Sources   Download

The Requires

 

20/04 2015

0.1.6

0.1.6.0

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

  Sources   Download

The Requires

 

17/04 2015

0.1.5

0.1.5.0

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

  Sources   Download

The Requires

 

15/05 2014

0.1.4

0.1.4.0

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

  Sources   Download

The Requires

 

09/05 2014

v0.1.1

0.1.1.0

CakePHP 2.x component for dynamically loading content as bits into a page matched by route.

  Sources   Download

The Requires