Re: $form-file() renders: Array to string conversion [COREcakelibs/view/helper.php, line 296]

2007-08-16 Thread brammeleman

I'm getting the same error with cake 1.2 5427. I'm not doing any
validation / upload behaviors or what so ever.

This is my code:
controller action:

function add_picture() {
if (!empty($this-data)) {
$this-Post-create();
if ($this-Post-save($this-data)) {
$post_id = $this-Post-getInsertID();
// store uploaded file

move_uploaded_file($this-data['Post']['upload']['tmp_name'],
IMAGES_PATH . $post_id . '.jpg');
$this-Session-setFlash('The picture is 
saved!');
$this-redirect('/posts');
} else {
$this-Session-setFlash('The Picture upload 
failed. Please, try
again.');
}
}
}

view (views/posts/add_picture.ctp):
?php

echo $form-create('Post', array('action' = 'add_picture',
'type'='file'));

echo $form-input('title');
echo $form-file('upload', array('label' = 'Picture'));

echo $form-end('Submit');

?

After submitting the empty form it returns the error:

Notice (8): Array to string conversion [CORE/cake/libs/view/
helper.php, line 298]

The problem seems to be caused by the file() function of the
formHelper class. A simple fix is adding the following lines to [CORE]/
cake/libs/view/helpers/form.php:

find (line ~829):
function file($fieldName, $options = array()) {
$options = $this-__initInputField($fieldName, $options);
$this-__secure();

insert:
if (isset($options['value'])) {
unset($options['value']);
}

Note that this is a fix that works for me but might a fix for a side
effect of the real problem.

Bests,

Bram

On Jun 27, 7:42 am, abba bryant [EMAIL PROTECTED] wrote:
 I was getting this same issue. What fixed it for me was making sure the app



 dardosordi wrote:

  Can you post your entire model,  I want to see your $valdiatearray.
  Try removing the validation from the file field, if that works, try
  the new version of the upload behaviour (http://bin.cakephp.org/saved/
  20438).

  On Jun 20, 9:05 pm, mastorna [EMAIL PROTECTED] wrote:
  I believe this topic has come up few times, but after searching the
  archives, I'm at a complete loss at how to solve it.  I'm doing a file
  upload and I repeatly receive the same error.

 Arraytostringconversion[CORE/cake/libs/view/helper.php,line296]

  so i've got an input type of file using the view and formHelper:

  VIEW:

  $form-file(Model.name);  // in this case: Mixtape.filename
  echo $form-label('Mixtape.artist',Artists:);
  echo $form-input('Mixtape.artist',array('div' = true, 'label' =
  false, 'class'='required', 'error' =array( 0 = 'Please provide a
  valid artist', 1 = 'The artist must have at least 2 or more
  characters' )));

  CONTROLLER:

  if ($this-Mixtape-save($this-data))
  {
   $this-flash('Your post has been saved.','/mixtape');

  }

  So when the controller passes this to the model, its going to pass the
  file ($_FILES) as anarray, which is understood.

  var $actsAs =array('Upload' =array(
  'filename' =array(
  'dir' = 'files/images',
  'overwrite_existing' =
  false,
  'create_directory' =
  false,
  'allowed_mime' =
 array('audio/mpeg','image/jpeg', 'image/
  pjpeg', 'image/gif', 'image/png'),
  'allowed_ext' =
 array('.mp3','.jpg', '.jpeg', '.png', '.gif'),
  )
  )
  );

  When I hit submit, the data passes to the model and cakePHP spits out
  out this error.  How do I solve for this?

 --
 View this message in 
 context:http://www.nabble.com/%24form-%3Efile%28%29-renders%3A-Array-to-strin...
 Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: $form-file() renders: Array to string conversion [COREcakelibs/view/helper.php, line 296]

2007-06-26 Thread abba bryant


I was getting this same issue. What fixed it for me was making sure the app

dardosordi wrote:
 
 
 Can you post your entire model,  I want to see your $valdiate array.
 Try removing the validation from the file field, if that works, try
 the new version of the upload behaviour (http://bin.cakephp.org/saved/
 20438).
 
 On Jun 20, 9:05 pm, mastorna [EMAIL PROTECTED] wrote:
 I believe this topic has come up few times, but after searching the
 archives, I'm at a complete loss at how to solve it.  I'm doing a file
 upload and I repeatly receive the same error.

 Array to string conversion [CORE/cake/libs/view/helper.php, line 296]

 so i've got an input type of file using the view and formHelper:

 VIEW:

 $form-file(Model.name);  // in this case: Mixtape.filename
 echo $form-label('Mixtape.artist',Artists:);
 echo $form-input('Mixtape.artist', array('div' = true, 'label' =
 false, 'class'='required', 'error' = array( 0 = 'Please provide a
 valid artist', 1 = 'The artist must have at least 2 or more
 characters' )));

 CONTROLLER:

 if ($this-Mixtape-save($this-data))
 {
  $this-flash('Your post has been saved.','/mixtape');

 }

 So when the controller passes this to the model, its going to pass the
 file ($_FILES) as an array, which is understood.

 var $actsAs = array('Upload' = array(
 'filename' = array(
 'dir' = 'files/images',
 'overwrite_existing' =
 false,
 'create_directory' =
 false,
 'allowed_mime' =
 array('audio/mpeg','image/jpeg', 'image/
 pjpeg', 'image/gif', 'image/png'),
 'allowed_ext' =
 array('.mp3','.jpg', '.jpeg', '.png', '.gif'),
 )
 )
 );

 When I hit submit, the data passes to the model and cakePHP spits out
 out this error.  How do I solve for this?
 
 
  
 
 

-- 
View this message in context: 
http://www.nabble.com/%24form-%3Efile%28%29-renders%3A-Array-to-string-conversion--CORE-cake-libs-view-helper.php%2C-line-296--tf3955798.html#a11318726
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---