dbrisinajumi/d2files

文件上传器

安装: 269

依赖: 3

建议者: 0

安全: 1

星标: 1

关注者: 5

分支: 1

公开问题: 2

类型:yii-extension

1.0.0 2015-03-23 08:30 UTC

This package is auto-updated.

Last update: 2024-09-04 15:54:05 UTC


README

功能

  • 将文件附加到模型记录
  • 模型视图小部件

安装

php composer.phar require dbrisinajumi/d2files dev-master
  • 添加到 config/main.php
     'import' => array(
        'vendor.dbrisinajumi.d2files.models.*',
        'vendor.dbrisinajumi.d2files.widgets.*', // shared classes
    ),
    'modules' => array(
        'd2files' => array(
            'class' => 'vendor.dbrisinajumi.d2files.D2filesModule',
            'upload_dir' => 'root.upload',
            'accept_file_types' => '/\.(gif|pdf|dat|jpe?g|png|doc|docx|xls|xlsx|htm)$/i',
            
            //automaticly registre tasks, when upload files to model 
            // d2person.PprsPerson, if user role is Agent or Client
            'registre_tasks_to_models' => array(
                'd2person.PprsPerson' => array(
                    'new_project_status' => 1, //Not started
                    'task_init_status' => 1, //Active
                    'task_due_in_days' => 3,
                    'user_roles' => array('Agent','Client'),
                    ),
            ),
            'shareable_by_link' => [
                'my_module.my_model' => [
                    'allow_ip' => [
                        '127.0.0.1',
                        ],
                    'salt' => '1212133243243',
                ]
            ]
         ),  
	 ),
  • 在 config/console.php 的 commandMap 下添加
	'd2files' => 'vendor.dbrisinajumi.d2files.migrations', 
  • 执行 yiic 迁移
  • 在表 d2files 中可以定义模型的文件类型。

用法

视图

    $this->widget('d2FilesWidget',[
        'module'=>$this->module->id, 
        'model'=>$model,
        'title'=> 'Wiget Title',
        'icon' => false,
        'hideTitle' => false,
        'readOnly' => false,
        'showImagesTypes' => '/\.(gif|jpe?g|png)$/i'
        ]
        );

要求

  • 要上传文件,用户必须对调用模块具有 "ModuleName.ModelName.uploadD2File" 访问权限
  • 要删除文件,用户必须对调用模块具有 "ModuleName.ModelName.deleteD2File" 访问权限
  • 要下载、上传或删除文件,用户必须具有读取相应项的访问权限以及 "ModuleName.ModelName.downloadD2File" 访问权限

授予访问权限的 SQL 语句示例

INSERT INTO `authitem` 
(`name`, `type`, `description`, `bizrule`, `data`) 
VALUES
('D2company.CcmpCompany.uploadD2File','0','D2company.CcmpCompany upolad D2Files',NULL,'N;'),
('D2company.CcmpCompany.downloadD2File','0','D2company.CcmpCompany downloas D2Files',NULL,'N;'),
('D2company.CcmpCompany.deleteD2File','0','D2company.CcmpCompany delete D2Files',NULL,'N;')
;

INSERT INTO `authitemchild` (`parent`, `child`) VALUES ('Agent', 'D2company.CcmpCompany.uploadD2File'); 
INSERT INTO `authitemchild` (`parent`, `child`) VALUES ('Agent', 'D2company.CcmpCompany.downloadD2File'); 
INSERT INTO `authitemchild` (`parent`, `child`) VALUES ('Agent', 'D2company.CcmpCompany.deleteD2File');