Skip to content

Instantly share code, notes, and snippets.

@markstory
Created July 22, 2016 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markstory/d344cff70c1a8d21d2f0cf50fd9262ba to your computer and use it in GitHub Desktop.
Save markstory/d344cff70c1a8d21d2f0cf50fd9262ba to your computer and use it in GitHub Desktop.
issue 9152
<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Event\Event;
use Cake\Mailer\MailerAwareTrait;
/**
* Bookmarks Controller
*
* @property App\Model\Table\BookmarksTable $Bookmarks
*/
class BookmarksController extends AppController
{
public $components = ['RequestHandler', 'Paginator'];
/**
* Index method
*
* @return void
*/
public function index()
{
$options = [
'limit' => 5,
'sortWhitelist' => ['name', 'create'],
'order' => ['name' => 'asc']
];
$query = $this->Bookmarks->find()
->select(['name' => 'Bookmarks.title', 'create' => 'Bookmarks.created'])
->autoFields(true);
$this->set('bookmarks', $this->Paginator->paginate($query, $options));
$this->set('_serialize', ['bookmarks']);
}
}
<div class="bookmarks index large-10 medium-9 columns">
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><?= $this->Paginator->sort('user_id') ?></th>
<th><?= $this->Paginator->sort('name') ?></th>
<th><?= $this->Paginator->sort('create', 'Created At') ?></th>
<th><?= $this->Paginator->sort('updated') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($bookmarks as $bookmark): ?>
<tr>
<td>
<?= $bookmark->has('user') ? $this->Html->link($bookmark->user->id, ['controller' => 'Users', 'action' => 'view', $bookmark->user->id]) : '' ?>
</td>
<td><?= h($bookmark->title) ?></td>
<td><?= $this->Time->i18nFormat($bookmark->created) ?></td>
<td><?= h($bookmark->updated) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $bookmark->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $bookmark->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $bookmark->id], ['confirm' => __('ingAre you sure you want to delete # {0}?', $bookmark->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(__('next') . ' >') ?>
</ul>
<p><?= $this->Paginator->counter() ?></p>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment