Created
October 20, 2018 14:30
-
-
Save dmsysop/c2c30d760fb7d26a36f0a5068d87cd80 to your computer and use it in GitHub Desktop.
Exemplo de Chamada utilizando o sistema de Plugins do CakePHP
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
#Os dados aqui, são recebidos pela view DO PLUGIN Dropzone que é renderizada quando eu chamo (neste exemplo: eventos/galeria/id) | |
#O próprio DropZoneJS faz via loop, a inserção das imagens, por isto é um save simples sem precisar utilizar arrays, etc... | |
public function admin_add($file = null) { | |
if ($this->request->is('post')) { | |
if ($this->request->is('ajax')) { | |
$this->request->data['Dropzone'] = $_FILES['file']; | |
$this->request->data['Dropzone']['model_name'] = CakeSession::read('DropZoneModel'); | |
$this->request->data['Dropzone']['model_id'] = CakeSession::read('DropZoneModelId'); | |
$this->Dropzone->create(); | |
if ($this->Dropzone->save($this->request->data['Dropzone'])) { | |
return true; | |
} | |
} | |
} | |
} |
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
# $id é o ID do EVENTO que será gravado na tabela galerias (controlada pelo Plugin "Dropzone") no campo model_id | |
# Ainda na tabela galerias, o campo model_name, recebe o nome do Model (ex: Evento - neste caso) | |
public function admin_galeria($id) { | |
$conditions = array('Dropzone.model_id' => $id, 'Dropzone.model_name' => $this->modelClass); | |
$order = array('Dropzone.ordername ASC'); | |
$this->request->data = $this->Evento->Dropzone->find('all', compact('conditions', 'order')); | |
CakeSession::write('DropZoneModel', $this->modelClass); | |
CakeSession::write('DropZoneModelId', $id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment