Markdown plugin for CakePHP
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
Config
Controller/Component
Lib/Error
Model/Behavior
Vendor/MarkdownExtra
View
README.md
composer.json

README.md

Markdown plugin for CakePHP

This plugin facilitates the use of PHP Markdown with CakePHP

PHP Markdown is a port to PHP of the Markdown program written by John Gruber.

“Markdown” is two things: a plain text markup syntax, and a software tool that converts the plain text markup to HTML for publishing on the web.

More info: http://michelf.com/projects/php-markdown

For this plugin, the application Markdown is inside Vendor

Version

Written for CakePHP 2.x

Copyright

Copyright (c) 2011 Maury M. Marques

Installation

You can install this plugin using Composer, GIT Submodule, GIT Clone or Manually

[Using Composer]

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

{
  "require": {
    "maurymmarques/markdown-plugin": "dev-master"
  },
  "extra": {
    "installer-paths": {
      "app/Plugin/Markdown": ["maurymmarques/markdown-plugin"]
    }
  }
}

Then just run composer install

Because this plugin has the type cakephp-plugin set in it's own composer.json, composer knows to install it inside your /Plugin directory, rather than in the usual vendors file.

[GIT Submodule]

In your app directory (app/Plugin) type:

git submodule add git://github.com/maurymmarques/markdown-cakephp.git Plugin/Markdown
git submodule init
git submodule update

[GIT Clone]

In your plugin directory (app/Plugin or plugins) type:

git clone https://github.com/maurymmarques/markdown-cakephp.git Markdown

[Manual]

  • Download the Markdown archive.
  • Unzip that download.
  • Rename the resulting folder to Markdown
  • Then copy this folder into app/Plugin/ or plugins

Configuration

Bootstrap the plugin in app/Config/bootstrap.php:

CakePlugin::load(array('Markdown' => array('bootstrap' => true)));

Usage

Enable the helper using the plugin syntax

If desired, set the component to assist with the return of data from the markdown.

// in app/Controller/BakeriesController.php
class BakeriesController extends AppController {

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

        public function index() {
            $this->set('textInMarkdownFormat', $yourTextInMarkdownFormat);
        }
}

Or, if the markdown content is in a file...

// in app/Controller/BakeriesController.php
class BakeriesController extends AppController {

        public $helpers = array('Markdown.Markdown');
        public $components = array('Markdown.Markdown');

        public function index() {
            $this->set('textInMarkdownFormat', $this->Markdown->getFile($pathToMarkdownFile));
        }
}

In the view you can use something like:

// in app/View/Bakeries/index.ctp
echo $this->Markdown->transform($textInMarkdownFormat);

In the model you can use something like:

// in app/Model/Bakery.php
class BakeryModel extends AppModel {

    public $actsAs = array('Markdown.Markdown');

    public function beforeSave($options = array()) {
        $this->data[$this->alias]['text_html'] = $this->transform( $this->data[$this->alias]['text_md'] );
        return true;
    }
}