CakePHP Download Plugin: Doesn't load as an attachment

I am using (or trying) to download a plugin from Jose Gonzalez: https://github.com/josegonzalez/upload and I want to save my image records in a separate table. I followed readme on github, but does not indicate how to enable this feature in add / edit and controller views. Here is what I have done so far:

application / model / image.php:

class Image extends AppModel {

    public $actsAs = array(
      'Upload.Upload' => array(
        'image' => array(
          'thumbnailSizes' => array('thumb' => '20x20')
        ),
      ),
    );

    public $belongsTo = array(
      'Profession' => array(
        'className' => 'Profession',
        'foreignKey' => 'foreign_key'
      )
    );

}

application / model / Profession.php:

class Profession extends AppModel {

    public $hasMany = array(
      'Image' => array(
        'className' => 'Image',
        'foreignKey' => 'foreign_key',
        'conditions' => array(
          'Image.model' => 'Profession'
        )
      )
    );

}

app / View / Professions / add.php (corresponding part):

$this->Form->input('Image.image', array('type' => 'file', 'label' => ''));

Application / Controller / ProfessionsController.php:

public function add() {
  if ($this->request->is('post')) {
    if ($this->Profession->saveAll($this->request->data)) {
      $this->redirect(array('action' => 'index'));
    } else {
      $this->Session->setFlash(__('Error'));
    }
  }
}

the file does not load, and the entry in my table imageslooks like this:

id | model | foreign_key | name     | image | dir  | type      | size | active
---+-------+-------------+----------+-------+------+-----------+------+--------
 1 |       |           1 | test.png |       | NULL | image/png |  814 |      1

model, image and catalog should not be empty / null.

debug output debug($this->request->data)from add()-function:

array(
    'Profession' => array(
        [...]
    ),
    'Image' => array(
        'image' => array(
            'name' => 'test.png',
            'type' => 'image/png',
            'tmp_name' => '/Applications/MAMP/tmp/php/phpTMHMF9',
            'error' => (int) 0,
            'size' => (int) 1473
        )
    )
)

, , , . , , , .

+5
2

, , ( 4 ), , .

() (app\Model\Upload.php)

class Upload extends AppModel {
    public $actsAs = array(
        'Upload.Upload' => array('upload')
    );

    public $belongsTo = array(
        'Product' => array(
            'className' => 'Product',
            'foreignKey' => 'foreign_key'
        )
    );
}

(app\Model\Product.php)

class Product extends AppModel {
    public $hasMany = array(
        'Image' => array(
            'className' => 'Upload',
            'foreignKey' => 'foreign_key',
            'conditions' => array(
                'Image.model' => 'Product'
            )
        )
    );

    // rest of the code
}

:

id | model | foreign_key | name     | upload | dir  | type       | size | active
---+-------+-------------+----------+--------+------+------------+------+--------
 1 |       |           1 | test.jpg |        | NULL | image/jpeg | 5820 |      1

2 (appView\Products\add.ctp)

echo $this->Form->create('Product', array('type' => 'file'));
echo $this->Form->input('name');
echo $this->Form->input('Image.upload.upload', array('type' => 'file'));
echo $this->Form->input('Image.upload.model', array('type' => 'hidden', 'value' => 'Product'));
echo $this->Form->end('Save Product');

, , . :

this->Form->input('Image.image.image', array('type' => 'file', 'label' => ''));
+2

:

echo $this- > Form > input ('Attachment.1.model', array ('type' = > 'hidden', 'value' = > 'Sludge'));

.

0

All Articles