我要做的就是在保存之前从控制器更改上传模型的 $actsAs 数组中的值(“路径”)。
我想出的唯一方法是卸载行为,然后使用它的所有设置加载它。
仅仅改变路径似乎有点过头了。有没有更简单/更好的方法?
$this->loadModel('Upload');
$this->Upload->Behaviors->unload('Upload.Upload');
$this->Upload->Behaviors->load('Upload.Upload', array(
'photo' => array(
'thumbnailSizes' => array(
'xvga' => '1024x768',
'vga' => '640x480',
'thumb' => '80x80',
),
'thumbnailMethod' => 'php',
'thumbnailQuality' => '80',
'pathMethod'=>'random',
'path' => '{ROOT}webroot{DS}uploads{DS}test{DS}{field}{DS}',
'maxSize' => '5242880', //5MB
'mimetypes' => array('image/jpeg', 'image/png', 'image/gif', 'image/bmp'),
'extensions' => array('jpg', 'gif', 'png', 'bmp'),
),
));
if($this->Upload->save($this->request->data)) {
//...