Skip to content

Instantly share code, notes, and snippets.

@arodu
Created January 10, 2022 17:24
Show Gist options
  • Save arodu/5325467ac18e4ea8b95624e5873b2af9 to your computer and use it in GitHub Desktop.
Save arodu/5325467ac18e4ea8b95624e5873b2af9 to your computer and use it in GitHub Desktop.
cakephp ListAction for AppController
<?php
/**
* List action
*/
public function list()
{
$alias = $this->loadModel()->getAlias();
$options = $this->getRequest()->getQuery();
if (method_exists($this->loadModel(), 'get' . $alias . 'List')) {
$list = $this->loadModel()->{'get' . $alias . 'List'}($options);
} else {
$list = $this->loadModel()->find('list', $options);
}
$this->set(strtolower($alias), $list);
$this->viewBuilder()->setOption('serialize', [strtolower($alias)]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment