CakePHP 框架的工具

euromark cc785f7cc6 composer 11 年之前
src 0f40f5e29b casing 11 年之前
tests be573ee676 Correct namespace 11 年之前
.coveralls.yml 7a03eaee62 another test 11 年之前
.gitignore 6ee8a8bd7c badges 11 年之前
.scrutinizer.yml 987acd04dd update bootstrap 11 年之前
.travis.yml d5f8f3417e travis 11 年之前
README.md 6a59fed3b4 readme 11 年之前
composer.json cc785f7cc6 composer 11 年之前
phpunit.xml.dist 5488ae4c6c Upgrade RssView 11 年之前

README.md

CakePHP Tools Plugin

Build Status License Total Downloads

A CakePHP 3.x Plugin containing several useful tools that can be used in many projects.

Version notice

This cake3 branch only works for CakePHP3.x - please use the master branch for CakePHP 2.x!

How to include

Installing the Plugin is pretty much as with every other CakePHP Plugin.

Put the files in APP/Plugin/Tools, using Packagist/Composer:

"require": {
	"dereuromark/cakephp-tools": "dev-cake3"
}

and

composer update

Details @ https://packagist.org/packages/dereuromark/cakephp-tools

That's it. It should be up and running.

The basics

This will load the plugin:

Plugin::load('Tools');

or

Plugin::loadAll();

In case you want the Tools bootstrap file included (recommended), you can do that in your APP/Config/bootstrap.php with

Plugin::load('Tools', array('bootstrap' => true));

or

Plugin::loadAll(array(
		'Tools' => array('bootstrap' => true
));

Namespacing

Using Cake3 and namespaces, don't forget to add "Tools" as namespace to new files. Also don't forget the use statements.

If you create a new behavior in the plugin, it might look like this:

namespace Tools\Model\Behavior;

use Cake\ORM\Behavior;

class CoolBehavior extends Behavior {
}

For a new APP behavior "MySlugged" that extends "Tools.Slugged" it is:

namespace App\Model\Behavior;

use Tools\Model\Behavior\SluggedBehavior;

class MySluggedBehavior extends SluggedBehavior {
}

Note that use statements should be in alphabetical order. See CakePHP coding standards for details.

Internal handling via plugin dot notation

Internally (method access), you don't use the namespace declaration. The plugin name suffices:

// In a Table
$this->addBehavior('Tools.Slugged'); // Adding SluggedBehavior

// In a Controller
public $helpers = array('Tools.Foo'); // Adding FooHelper

Testing

You can test using a local installation of phpunit or the phar version of it:

cd Plugin/Tools
composer update
phpunit

To test a specific file:

phpunit /path/to/class.php

TODOs

  • Move more 2.x stuff to 3.x