This repository was archived by the owner on Nov 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Gallery Usage
zuha edited this page Jul 5, 2012
·
2 revisions
Attaching a gallery to any model is pretty straight forward code.
Make sure your form is of the file type
echo $this->Form->create('Task', array('type' => 'file'));
Then add these inputs
echo $this->Form->input('GalleryImage.filename', array('type' => 'file', 'label' => 'Upload your best image for this item.', 'after' => ' <p> You can add additional images after you save.</p>'));
echo $this->Form->input('GalleryImage.dir', array('type' => 'hidden'));
echo $this->Form->input('GalleryImage.mimetype', array('type' => 'hidden'));
echo $this->Form->input('GalleryImage.filesize', array('type' => 'hidden'));
public $hasOne = array(
'Gallery' => array(
'className' => 'Galleries.Gallery',
'foreignKey' => 'foreign_key',
'dependent' => false,
'conditions' => array('Gallery.model' => 'Task'),
'fields' => '',
'order' => ''
),
);
function afterSave() {
$this->data['Gallery']['model'] = $this->alias;
$this->data['Gallery']['foreign_key'] = $this->id;
// check if GalleryImage data is in data
if (isset($this->data['GalleryImage'])){
if ($this->data['GalleryImage']['filename']['error'] == 0
&& $this->Gallery->GalleryImage->add($this->data, 'filename')) {
return true;
} else {
return false;
}
}
}