Re: Media Plugin - Newbie Questions

2011-02-21 Thread kdubya
I don't know anything about the Media plugin, however your problem may
be with how you have created your inputs in the view. Have you looked
at the structure of $this->data once the form has been submitted to
your action (admin_add)? In order for saveAll() to work. It should
look something like:

array(
  [PressRelease]=>array(
[date]=>// some date
. // other fields
.
  [Attachment]=>array(
[file]=>// some file name

In your view you have:
echo $this->Form->input('file', array('label' => 'File', 'type'
=>'file'));

It may be as simple as changing this to:
echo $this->Form->input('Attachment.file', array('label' => 'File',
'type' =>'file'));

BTW, saveAll() will save related model data ONLY if the array passed
is properly structured AND it is only one level deep.

HTH,
Ken

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Media Plugin - Newbie Questions

2011-02-21 Thread mjhnlca
I'm trying to set up the Media plugin, but am having problems.

I have a PressRelease model, and while adding an entry I would like to
choose and upload a PDF file to associate with it. But when adding an
entry, the press_releases table receives an entry, and the attachment
table does not. *If I use the baked Attachment view to add an entry
the attachments table DOES receive the row.

I have followed the documentation, updated the bootstrap file, etc.
Below is the relevant code from the Press Release model, controller
and view.

If you have any idea what I correct, please advise. Thanks!

A few simple questions also:
1. Do I need to add this ...
var $helpers = array('Media.Media');
... to my PressRelease model?

2. Do I need to add "belongsTo" data to the Attachment model?

-- Code Provided Below --

The Press Release model has this:

   var $hasOne = array(
  'Attachment' => array(
  'className' => 'Media.Attachment',
  'foreignKey' => 'foreign_key',
  'conditions' => array('Attachment.model' => 'PressRelease'),
  'dependent' => true,
   ));

The Press Release controller has this:

function admin_add() {
$this->layout = 'admin';
if (!empty($this->data)) {
$this->PressRelease->create();
if ($this->PressRelease->saveAll($this->data, 
array('validate' =>
'first'))) {
$this->Session->setFlash('The press release has 
been saved.',
'flash_success');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('The press release 
could not be saved.
Please, try again.', 'flash_error');
}
}
$projects = $this->PressRelease->Project->find('list');
$this->set(compact('projects'));
}

The form in the view looks like this:


Form->create('PressRelease', array('enctype' =>
'multipart/form-data'));?>


Form->input('date', array('type'=>'date',
'minYear'=>2005, 'maxYear'=>$max_year, 'selected'=>$unix_timestamp));
echo $this->Form->input('title');
echo $this->Form->input('file', array('label' => 'File', 'type' 
=>
'file'));
echo $this->Form->input('Project',array('label'=>'Related
Project(s)', 'multiple' => 'checkbox'));
?>

Form->end(__('Add Press Release', true));?>


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php