Skip to content

Instantly share code, notes, and snippets.

@damianoporta
Created November 3, 2015 09:39
Show Gist options
  • Save damianoporta/93015169fb9c9f7aed8f to your computer and use it in GitHub Desktop.
Save damianoporta/93015169fb9c9f7aed8f to your computer and use it in GitHub Desktop.
/**
* Richiesta ajax per ricerca Tags
*
* Parametri:
* - scope: intero o array di interi che indica lo scope dei tags desiderati
* - query: digitazione dell'utente
*
* @return type
*/
public function getDataAjax()
{
// Carico il componente ajax
$this->loadComponent('Ajax.Ajax', [
'flashKey' => false
]);
//$this->request->allowMethod('ajax');
$tags = $this->Tags->find()->select(['Tags.id', 'Tags.tag_name']);
if (!empty($this->request->query['scope'])) {
if (!is_array($this->request->query['scope'])) {
$this->request->query['scope'] = [$this->request->query['scope']];
}
$tags->where(['Tags.scope' => $this->request->query['scope']], ['Tags.scope' => 'integer[]']);
}
if (!empty($this->request->query('query'))) {
$tags->where(['Tags.tag_name LIKE' => '%' . $this->request->query('query') . '%']);
}
$data = $tags->order('Tags.tag_name ASC')->toArray();
$this->set(compact('data'));
$this->set('_serialize', ['data']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment