Skip to content

Instantly share code, notes, and snippets.

@jippi
Created May 3, 2014 16:58
Show Gist options
  • Select an option

  • Save jippi/247b9219f7c600f60b54 to your computer and use it in GitHub Desktop.

Select an option

Save jippi/247b9219f7c600f60b54 to your computer and use it in GitHub Desktop.
<?php
namespace App\Controller;
use Cake\Event\Event;
class PostsController extends AppController {
public $paginate = ['limit' => 5];
public function beforeFilter(Event $event) {
$fm = $this
->Crud
->listener('view')
->fields()
->all($this->Posts)
->field('is_active')
->input(['label' => 'Active'])
->alias('Active')
->end()
->field('comment_count')
->blacklist();
return parent::beforeFilter($event);
}
public function index() {
$fm = $this->Crud->listener('view')->fields();
$fm->field('id')->blacklist();
$this->Crud->on('beforePaginate', function(Event $event) {
$event->subject->object = $this->Posts->find('search', $this->request->query);
});
return $this->Crud->execute();
}
public function add() {
return (new \Crud\Action\AddAction($this))->handle();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment