davidyell/viewbits

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (0.1.11) of this package.

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

Installs: 287

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 0

Open Issues: 0

Type:cakephp-plugin

0.1.11 2016-03-17 16:13 UTC

This package is auto-updated.

Last update: 2024-01-13 01:23:39 UTC


README

Why?

I needed a way to allow certain blocks of content in a view to be content managed without affecting the layout.

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.

Compatability

Compatible with CakePHP 2.x. (Developed on 2.2.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.

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

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.

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

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.

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.

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

Example

<?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.

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.