dev-master
9999999-dev https://github.com/krolow/CobaiaAnnotationCakePHP Plugin with a collection of Annotations to use
MIT
The Requires
- php >=5.3.0
- composer/installers *
- doctrine/annotations 1.0
cakephp meta annotation
Wallogit.com
2017 © Pedro PelĂĄez
CakePHP Plugin with a collection of Annotations to use
Annotations in CakePHP., (*1)
CobaiaAnnotations make usage of composer, so download composer and create your app/composer.json, (*2)
{
"name": "testing",
"require": {
"php": ">=5.3.0",
"cakephp/debug_kit" : "*",
"cobaia/cobaia-annotation": "dev-master"
},
"minimum-stability": "dev"
}
It's time to running composer.phar install, (*3)
After install it's time to load the plugin, open app/Config/bootstrap.php, (*4)
CakePlugin::load('CobaiaAnnotation', array('bootstrap' => true));
//register filter
Configure::write('Dispatcher.filters', array(
'AssetDispatcher',
'CacheDispatcher',
'CobaiaAnnotation.AnnotationDispatcher'
));
<?php
App::uses('AppController', 'Controller');
use CobaiaAnnotation\Configuration\Controller\ParamConverter;
class ContentsController extends AppController {
/**
* @ParamConverter("content", class="Content")
*/
public function view($content = 1) {
var_dump($content);
}
}
ParamConverter will automatically converts the action paramter to data that is in the database., (*5)
So for example, using param coverter: call: /contents/view/20, (*6)
It would be the same as, (*7)
$content = $this->Content->read(null, $content);
<?php
App::uses('AppController', 'Controller');
use CobaiaAnnotation\Configuration\Controller\ViewHandler;
/**
* @ViewHandler(layout="ajax")
*/
class ContentsController extends AppController {
/**
* @ViewHandler(view="show")
*/
public function view() {
}
/**
* @ViewHandler(layout="default")
*/
public function index() {
}
}
ViewHandler will take care of your view, forget about $this->layout, $this->render(), just define in the annotation what layout you want to use and also what view, and that's it., (*8)
It makes also inheritance so if you define one layout or view in the class DocBlock, the actions will inherit the value., (*9)
<?php
App::uses('AppController', 'Controller');
use CobaiaAnnotation\Configuration\Controller\Loader\ModelLoader;
use CobaiaAnnotation\Configuration\Controller\Loader\ComponentLoader;
use CobaiaAnnotation\Configuration\Controller\Loader\HelperLoader;
/**
* @ModelLoader({"Content", "Fake"})
* @ComponentLoader({"Session", "RequestHandler"})
* @HelperLoader({"Text", "Time", "Number"})
*/
class ContentsController extends AppController {
public function view($content = 1) {
}
}
@Model, @Component, @Helper will handle to you the load of models, components and helpers, not needed anymore put the attribute of class in your code., (*10)
Licensed under The MIT License Redistributions of files must retain the above copyright notice., (*11)
VinĂcius Krolow - krolow[at]gmail.com, (*12)
CakePHP Plugin with a collection of Annotations to use
MIT
cakephp meta annotation