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
)
)
)
, , , .
, , , .