Skip to content

Instantly share code, notes, and snippets.

View mariuswilms's full-sized avatar

Marius Wilms mariuswilms

View GitHub Profile
<?php
class Movie extends AppModel {
var $actsAs = array('Media.Transfer');
var $validate = array(
'file' => array(
'resource' => array('rule' => 'checkResource'),
'access' => array('rule' => 'checkAccess'),
'location' => array('rule' => array('checkLocation', array(MEDIA_TRANSFER, '/tmp/'))),
'permission' => array('rule' => array('checkPermission', '*')),
<?php
class Movie extends AppModel {
// ...
var $hasMany = array(
'Attachment' => array(
'className' => 'Media.Attachment',
'foreignKey' => 'foreign_key',
'conditions' => array('Attachment.model' => 'Movie'),
'dependent' => true,
));
<?php
class Movie extends AppModel {
// ...
var $hasMany = array(
'Poster' => array(
'className' => 'Media.Attachment',
'foreignKey' => 'foreign_key',
'conditions' => array('Poster.model' => 'Movie', 'Poster.group' => 'poster'),
'dependent' => true,
),
#!/bin/bash
CAKE_CORE_INCLUDE_PATH=/usr/local/share/cake-1.2.x.x
CAKE_CONSOLE=${CAKE_CORE_INCLUDE_PATH}/cake/console/cake
APP="/path/to/your/app"
MODELS="example attachments" # Models separated by one space
AUTO="-auto" # Enables automatic (destructive) repair!
if [ ! -x $CAKE_CONSOLE ] || [ ! -x $APP ]; then
exit 1
<?php
class Example extends MediaAppModel
// ...
var $validate = array(
// ...
'extension' => array('rule' => array('checkExtension', // order: deny, allow
array('bin', 'class', 'dll', 'dms', 'exe'), // blacklist
array('jpg', 'tmp') // whitelist
),
),
<?php
// app/models/example.php
class Example extends AppModel {
var $actsAs = array('Media.Transfer');
}
// For single uploads
// app/controllers/examples_controller.php
class ExamplesController extends AppController {
function edit($id = null) {
<?php
// app/controllers/movies_controller.php
class MoviesController extends AppController {
function edit($id = null) {
// ...
// $this->data = array(
// 'Movie' => array('title' => 'Vicky Cristina Barcelona'),
// 'Attachment' => array(
// 0 => array('file' => transferable item1, 'model' => 'Movie'),
// 1 => array('file' => transferable item2, 'model' => 'Movie'),
<?php
class Movie extends AppModel {
// ...
var $hasOne = array(
'Attachment' => array(
'className' => 'Media.Attachment',
'foreignKey' => 'foreign_key',
'conditions' => array('Attachment.model' => 'Movie'),
'dependent' => true,
));
<?php
class Attachment extends AppModel {
// ...
function beforeMake($file, $process = array()) {
extract($process);
if ($this->alias == 'Avatar' && $version != 's') {
return true;
}
<?php
class MoviesController extends AppController {
function edit($id = null) {
/* For a single upload */
$this->data = array(
'Movie' => array(
'file' => 'transferable item here'
));
$this->Movie->save($this->data);