Created
November 3, 2015 09:39
-
-
Save damianoporta/93015169fb9c9f7aed8f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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