Skip to content

Instantly share code, notes, and snippets.

@milok
Created March 19, 2012 17:25
Show Gist options
  • Save milok/2120149 to your computer and use it in GitHub Desktop.
Save milok/2120149 to your computer and use it in GitHub Desktop.
Model used with upload plugin
<?php
App::uses('AppModel', 'Model');
/**
* Picture Model
*
* @property Gallery $Gallery
* @property Job $Job
*/
class Picture extends AppModel {
public $actsAs = array(
'Upload.Upload' => array(
'image' => array(
'fields' => array(
'dir' => 'dir',
'type' => 'type',
'size' => 'size'
),
'path' => '..{DS}public_html{DS}files{DS}{model}{DS}{field}{DS}',
'thumbsizes' => array(
'anteprima' => '220x220',
'slide' => '370l',
'thumb' => '80x80'
),
'thumbnailMethod' => 'php',
'deleteOnUpdate' => 'true',
'mimetypes' => array('png', 'jpg')
)
)
);
/**
* Display field
*
* @var string
*/
public $displayField = 'name';
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'job_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'name' => array(
'notempty' => array(
'rule' => array('notempty'),
),
),
'image' => array(
'isCompletedUpload' => array(
'rule' => 'isCompletedUpload',
'message' => 'File was not successfully uploaded'
),
'isBelowMaxSize' => array(
'rule' => array('isBelowMaxSize', 10485760), //10MB
'message' => 'File is larger than the maximum filesize'
),
'noPhpExtensionErrors' => array(
'rule' => 'noPhpExtensionErrors',
'message' => 'File was not uploaded because of a faulty PHP extension'
),
'isSuccessfulWrite' => array(
'rule' => 'isSuccessfulWrite',
'message' => 'File was unsuccessfully written to the server'
)
),
'main' => array(
'boolean' => array(
'rule' => array('boolean'),
),
),
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Gallery' => array(
'className' => 'Gallery',
'foreignKey' => 'gallery_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Job' => array(
'className' => 'Job',
'foreignKey' => 'job_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment