netcommons / files
NetCommons 插件文件
3.3.7.2
2024-05-28 05:17 UTC
Requires
- cakedc/migrations: ~2.2
- josegonzalez/cakephp-upload: 1.*|2.*
- netcommons/authorization-keys: @dev
- netcommons/blocks: @dev
- netcommons/net-commons: @dev
- netcommons/site-manager: @dev
- dev-master
- 3.3.7.2
- 3.3.7.1
- 3.3.7.0
- 3.3.6.4
- 3.3.6.3
- 3.3.6.2
- 3.3.6.1
- 3.3.6.0
- 3.3.5.1
- 3.3.5.0
- 3.3.4.2
- 3.3.4.1
- 3.3.4.0
- 3.3.3.1
- 3.3.3.0
- 3.3.2.1
- 3.3.2.0
- 3.3.1.2
- 3.3.1.1
- 3.3.1.0
- 3.3.0.1
- 3.3.0
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.10
- 3.1.9
- 3.1.8
- 3.1.7
- 3.1.6
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.0
- 3.0.1
- 3.0.0
- dev-availability
- dev-fix/editProblem
- dev-develop
This package is auto-updated.
Last update: 2024-09-08 06:26:26 UTC
README
AttachmentBehavior
当显示文件上传表单时,请将 Model::recursive 设置为 0 或更大。
如果 Model::recursive = -1,则无法获取 Model 中附加的文件信息,因此 NetCommonsForm::uploadFile() 会错误地判断没有附加文件。
认证密钥组合使用方法
通过将 认证密钥插件 与之结合,只有知道特定认证密钥的用户才能下载文件。
重定向类型
在实现下载动作的控制器中使用 AuthorizationKeyComponent。
public $components = array( 'Files.Download', 'AuthorizationKeys.AuthorizationKey' => [ 'operationType' => 'redirect', 'targetAction' => 'download_pdf', 'model' => 'BlogEntry', ], );
在下载动作内设置基于认证密钥的守卫。
public function download_pdf() { // ここから元コンテンツを取得する処理 $this->_prepare(); $key = $this->params['pass'][1]; $conditions = $this->BlogEntry->getConditions( Current::read('Block.id'), $this->Auth->user('id'), $this->_getPermission(), $this->_getCurrentDateTime() ); $conditions['BlogEntry.key'] = $key; $options = array( 'conditions' => $conditions, 'recursive' => 1, ); $blogEntry = $this->BlogEntry->find('first', $options); // ここまで元コンテンツを取得する処理 // 認証キーによるガード $this->AuthorizationKey->guard('redirect', 'BlogEntry', $blogEntry); // ダウンロード実行 if ($blogEntry) { return $this->Download->doDownload($blogEntry['BlogEntry']['id'], ['filed' => 'pdf']); } else { // 表示できない記事へのアクセスなら404 throw new NotFoundException(__('Invalid blog entry')); } }
弹出类型
在实现下载动作的控制器中使用 AuthorizationKeyComponent。
public $components = array( 'Files.Download', 'AuthorizationKeys.AuthorizationKey' => [ 'operationType' => 'redirect', 'targetAction' => 'download_pdf', 'model' => 'BlogEntry', ], );
将下载动作内的守卫设置为弹出。
$this->AuthorizationKey->guard('popup', 'BlogEntry', $blogEntry);
将下载链接重写为显示弹出窗口,认证密钥弹出窗口作为 AngularJS 的指令 authorization-keys-popup-link 实现。
<div> PDF : <?php echo $this->Html->link('PDF', '#', ['authorization-keys-popup-link', 'url' => $this->NetCommonsHtml->url( [ 'action' => 'download_pdf', 'key' => $blogEntry['BlogEntry']['key'], 'pdf', ] ), 'frame-id' => Current::read('Frame.id') ] ); ?> </div>
有关认证密钥的详细信息,请参阅认证密钥文档。
验证
在 AttachmentBehavior 中可以使用 Upload 行为的验证规则。