Improve this Doc

Installation

Installing CRUD view requires only a few steps

Requirements

  • CakePHP 3.x

Getting the Code

The recommended installation method for this plugin is by using composer.

In your aplication forlder execute:

composer require friendsofcake/crud-view

It is highly recommended that you install the Search plugin as well:

composer require friendsofcake/search

Loading the plugin

Execute the following lines from your application folder:

bin/cake plugin load Crud
bin/cake plugin load CrudView
bin/cake plugin load BootstrapUI
bin/cake plugin load Search

Configuring the AppController

I you haven’t configured the CRUD plugin already add the following line to your src/Controller/AppController.php file

<?php
namespace App\Controller;

class AppController extends \Cake\Controller\Controller {

  use \Crud\Controller\ControllerTrait;

  public function initialize()
  {
    $this->viewClass = 'CrudView\View\CrudView';
    $this->loadComponent('Crud.Crud', [
          'actions' => [
            'Crud.Index',
            'Crud.View',
            'Crud.Add',
            'Crud.Edit',
            'Crud.Delete',
            'Crud.Lookup',
          ],
          'listeners' => [
              'CrudView.View',
              'Crud.Redirect',
              'Crud.RelatedModels',
              'CrudView.Search'
          ]
      ]);
  }
}

If you are familair with the CRUD plugin already, you will immediately understand that Crud view is simply a listener for the events generated by the plugin. If this is new to you, don’t worry, it will be explained in the following sections.

Using It In Your Controllers

Any controller inheriting from AppController will automatically implement the specified actions loaded int the CRUD component configuration. Therefore, you can just leave your controller code empty!

<?php
namespace App\Controller;

class CategoriesController extends AppController {
  // No code here, but we have all actions available to use!
}

View the Results

You can now access your categories list by pointing your browser to http://example.com/categories. Browse around your new Admin interface for each of the controllers you have in your application.