Parameter as array (cakephp)

0

I'm passing this an array containing data from a form, to a function, but in php it accuses this error. Can not use string offset as an array.

public function add($galeria_id) {
    if ($this->request->is('post')) {
        foreach ($this->request->data['Foto'] as $dados){
            $this->criarfoto($galeria_id, $dados);
        }
    }
    $this->render('form');
}

private function criarfoto($galeria_id, $file){
    $extension = pathinfo($file['imagem']['name'],PATHINFO_EXTENSION);
    $allowExt = array(
        'jpg',
        'jpeg',
        'png',
        'gif',
    );
    if(!in_array($extension, $allowExt)){
        return false;
    }
    $fotos_galeria = array(
        'galeria_id' => $galeria_id,
        'hot' => $file['hot'],
        'titulo' => $file['titulo'],
        'descricao' => $file['descricao'],
        'extension' => $extension,
    );
    $this->Foto->create();
    if ($this->Foto->save($fotos_galeria)){
        //continuação..

By the way, it is not setting the indexes of the other fields, the problem was this, when I give print_r to $file it returns a structure like this:

 Galeria de testesmichelakasdkasdasdArray

[name] => compre34.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php8f7w6H
[error] => 0
[size] => 25799

And the right thing would have to be a structure like this:

  Array

[titulo] => Galeria de testes,
[descricao] => michelakasdkasdasd,
[name] => compre34.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php8f7w6H
[error] => 0
[size] => 25799
    
asked by anonymous 20.04.2015 / 14:18

0 answers