Created
January 10, 2022 17:24
-
-
Save arodu/5325467ac18e4ea8b95624e5873b2af9 to your computer and use it in GitHub Desktop.
cakephp ListAction for AppController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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