Skip to content

Instantly share code, notes, and snippets.

@markstory
Last active August 29, 2015 14:23
Show Gist options
  • Save markstory/687276adeaead6458e19 to your computer and use it in GitHub Desktop.
Save markstory/687276adeaead6458e19 to your computer and use it in GitHub Desktop.
issue 6900
<?php
namespace App\Controller;
use Cake\Controller\Controller;
/**
* Application Controller
*
* Add your application-wide methods in the class below, your controllers
* will inherit them.
*
* @link http://book.cakephp.org/3.0/en/controllers.html#the-app-controller
*/
class AppController extends Controller
{
/**
* Initialization hook method.
*
* Use this method to add common initialization code like loading components.
*
* @return void
*/
public function initialize()
{
parent::initialize();
$this->loadComponent('Flash');
}
}
<?php
echo $this->Html->link(__('Delete Selected'),
['controller' => 'Portfolios', 'action' => 'delete'],
['id' => 'delete', 'class' => 'btn btn-danger hidden margin-left',
'confirm' => 'Are you sure you want to delete the selected portfolios?'
]
);
echo $this->Html->script('jquery');
?>
<input type="checkbox" checked name="delete_portfolio" class="delete" value="1">
<input type="checkbox" checked name="_csrfToken" class="delete" value="<?= $this->request->params['_csrfToken'] ?>">
<script>
$('a#delete').on('click', function(e) {
e.preventDefault();
$.post($(this).attr('href'), $('input.delete:checked').serialize());
})
</script>
<?php
namespace App\Controller;
use App\Controller\AppController;
class PortfoliosController extends AppController
{
public function initialize()
{
$this->loadComponent('RequestHandler');
$this->loadComponent('Csrf');
}
/**
* Index method
*
* @return void
*/
public function index()
{
// do nothing
}
public function delete() {
debug($this->request->is('ajax'));
debug($this->request->is('post'));
debug($this->request->data);
die();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment