PHP code example of oppara / cakephp-plugin-sortable
1. Go to this page and download the library: Download oppara/cakephp-plugin-sortable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
oppara / cakephp-plugin-sortable example snippets
// config/bootstrap.php
Plugin::load('Sortable');
// config/bootstrap.php
Plugin::loadAll();
// src/Model/Table/ArticlesTable.php
namespace App\Model\Table;
use Cake\ORM\Table;
class ArticlesTable extends Tabl
{
public function initialize(array $config)
{
$this->addBehavior('Sortable.Sortable', [
'condition_fields' => ['user_id']
]);
}
// src/Controller/ArticlesController.php
class ArticlesController extends AppController
{
public function sort()
{
if (!$this->request->is('ajax')) {
exit;
}
$data = json_encode($this->request->getData());
$this->log(__METHOD__ . ' data:' . $data, LOG_DEBUG);
$id = $this->request->getData('id');
$new_order = $this->request->getData('display_order');
$this->Sections->sort($id, $new_order);
return $this->response->withType('application/json')
->withStringBody(json_encode(['status' => 'OK']));
}