Created
September 18, 2016 19:41
-
-
Save frazr/e99e3262d1d7a74875b955c60a621273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* FilesTable */ | |
public function initialize(array $config) | |
{ | |
parent::initialize($config); | |
$this->table('files'); | |
$this->displayField('name'); | |
$this->primaryKey('id'); | |
$this->addBehavior('Timestamp'); | |
$this->hasMany('SubFolders', [ | |
'className' => 'Files', | |
'foreignKey' => 'parent_folder_id', | |
]); | |
$this->belongsTo('ParentFolders', [ | |
'className' => 'Files', | |
'foreignKey' => 'parent_folder_id', | |
]); | |
$this->belongsTo('MimeTypes', [ | |
'foreignKey' => 'mime_type_id', | |
'joinType' => 'INNER' | |
]); | |
$this->belongsToMany('Messages', [ | |
'foreignKey' => 'file_id', | |
'targetForeignKey' => 'message_id', | |
'joinTable' => 'files_messages' | |
]); | |
$this->belongsToMany('Users', [ | |
'foreignKey' => 'file_id', | |
'targetForeignKey' => 'user_id', | |
'joinTable' => 'files_users' | |
]); | |
} | |
/* Fetching */ | |
public function index() | |
{ | |
$this->viewBuilder()->template('home'); | |
$this->loadModel('Files'); | |
$folders = $this->Files->find()->where([ | |
'Files.is_dir' => 1, | |
'Files.parent_folder_id IS NULL' | |
])->order([ | |
'Files.filename' => 'ASC' | |
])->contain(['SubFolders']); | |
debug($folders->toArray()); | |
$this->set(compact('folders')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment