Skip to content

Instantly share code, notes, and snippets.

@nilsonpena
Created January 17, 2012 00:16
Show Gist options
  • Save nilsonpena/1623759 to your computer and use it in GitHub Desktop.
Save nilsonpena/1623759 to your computer and use it in GitHub Desktop.
Profile com MeioUpload
<div class="profiles form">
<?php echo $this->Form->create('Profile', array('type' => 'file'));?>
<fieldset>
<legend><?php echo __('Add Profile'); ?></legend>
<?php
echo $this->Form->input('user_id');
echo $this->Form->input('Avatar.filename', array('type' => 'file'));
echo $this->Form->input('Avatar.dir', array('type' => 'hidden'));
echo $this->Form->input('Avatar.mimetype', array('type' => 'hidden'));
echo $this->Form->input('Avatar.filesize', array('type' => 'hidden'));
echo $this->Form->input('email');
echo $this->Form->input('mes_nascimento');
echo $this->Form->input('dia_nascimento');
echo $this->Form->input('fone');
echo $this->Form->input('celular');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit'));?>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('List Profiles'), array('action' => 'index'));?></li>
<li><?php echo $this->Html->link(__('List Users'), array('controller' => 'users', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New User'), array('controller' => 'users', 'action' => 'add')); ?> </li>
<li><?php echo $this->Html->link(__('List Avatars'), array('controller' => 'avatars', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Avatar'), array('controller' => 'avatars', 'action' => 'add')); ?> </li>
</ul>
</div>
<?php
App::uses('AppModel', 'Model');
/**
* Avatar Model
*
* @property Profile $Profile
*/
class Avatar extends AppModel {
public $name = 'Avatar';
public $actAs = array(
'MeioUpload.MeioUpload' => array('filename')
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Profile' => array(
'className' => 'Profile',
'foreignKey' => 'profile_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
<?php
public function add() {
if ($this->request->is('post')) {
$this->Profile->create();
// debug($this->request->data);
// exit;
if ($this->Profile->save($this->request->data) && $this->Profile->Avatar->save($this->request->data)) {
$this->Session->setFlash(__('The profile has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The profile could not be saved. Please, try again.'));
}
}
$users = $this->Profile->User->find('list');
$this->set(compact('users'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment