|
|
11 年之前 | |
|---|---|---|
| src | 11 年之前 | |
| tests | 11 年之前 | |
| .coveralls.yml | 11 年之前 | |
| .scrutinizer.yml | 11 年之前 | |
| .travis.yml | 11 年之前 | |
| README.md | 11 年之前 | |
| composer.json | 11 年之前 | |
| phpunit.xml.dist | 11 年之前 |
A CakePHP 3.x Plugin containing several useful tools that can be used in many projects.
This cake3 branch only works for cake3 - please use the master branch for CakePHP 2.x!
Installing the Plugin is pretty much as with every other CakePHP Plugin.
Put the files in APP/Plugin/Tools, using packagist/composer:
"require": {
"dereuromark/tools-cakephp": "dev-cake3"
}
and
composer update
Details @ https://packagist.org/packages/dereuromark/tools-cakephp
That's it. It should be up and running.
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));
For Plugin::loadAll() it's
Plugin::loadAll(array(
'Tools' => array('bootstrap' => true
));
Using Cake3 and namespaces, don't forget to add "Dereuromark\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 Dereuromark\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 Dereuromark\Tools\Model\Behavior\SluggedBehavior;
class MySluggedBehavior extends SluggedBehavior {
}
Note that use statements should be in alphabetical order. See CakePHP coding standards for details.
As long as you don't have a "Tools" namespace already in use and if you want to save yourself some namespace typing in your APP, you can configure it the way that it does not need the the vendor name there:
Plugin::load('Tools', array('namespace' => 'Dereuromark\\Tools'));
For Plugin::loadAll() it's
Plugin::loadAll(array(
'Tools' => array('namespace' => 'Dereuromark\\Tools'
));
Personally, this is my default configuration for all plugins.
So for a new APP behavior "MySlugged" it is now:
namespace App\Model\Behavior;
use Tools\Model\Behavior\SluggedBehavior;
class MySluggedBehavior extends SluggedBehavior {
}
You can test using a local installation of phpunit or the phar version of it:
cd Plugin/Tools
phpunit --stderr
To test a specific file:
phpunit --stderr /path/to/class.php
Licensed under The MIT License unless specified otherwise (in the classes).