Skip to content

Instantly share code, notes, and snippets.

@guinslym
Last active January 3, 2016 00:09
Show Gist options
  • Save guinslym/8381010 to your computer and use it in GitHub Desktop.
Save guinslym/8381010 to your computer and use it in GitHub Desktop.
When I'm editing a picture (ImageController) I'm get the picture added in my database. So I'm having two pictures so the one that was already on the db and the new one. I'm using the https://github.com/josegonzalez/cakephp-upload plugin.
<div class="images form">
<?php echo $this->Form->create('Image', array('type' => 'file')); ?>
<fieldset>
<legend><?php echo __('Edit Image'); ?></legend>
<div class="alert alert-dismissable alert-success">
<button class="close" data-dismiss="alert" type="button">×</button>
<strong>Orientation and Filename</strong> must have values on "Edit" and on "Add"
</div>
<?php
echo $this->Form->input('file_name', array('type' => 'file'));
echo $this->Form->input('field', array(
'options' => array('landscape', 'portrait')
));
echo $this->Form->input('title');
echo $this->Form->input('caption');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $this->Form->value('Image.id')), null, __('Are you sure you want to delete # %s?', $this->Form->value('Image.id'))); ?></li>
<li><?php echo $this->Html->link(__('List Images'), array('action' => 'index')); ?></li>
</ul>
</div>
<?php
/**
* edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function edit($id = null) {
if (!$this->Image->exists($id)) {
throw new NotFoundException(__('Invalid image'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->Image->save($this->request->data)) {
$this->Session->setFlash(__('The image has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The image could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('Image.' . $this->Image->primaryKey => $id));
$this->request->data = $this->Image->find('first', $options);
}
}
?>
@guinslym
Copy link
Author

savant: echo $this->Form->input('id'); //on edit.ctp

Form->input('id'); echo $this->Form->input('file_name', array('type' => 'file')); echo $this->Form->input('field', array( 'options' => array('landscape', 'portrait') )); echo $this->Form->input('title'); echo $this->Form->input('caption'); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment