- Notifications
You must be signed in to change notification settings - Fork3
Romano83/CakePHP3-Media
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The aim of this plugin is to give you the ability to create and associate any kind of medias in your application.This plugin is the adapation fromGrafikart's Media Plugin for CakePHP 3.
- BelongsTo and hasMany Media association for you model;
- Upload using drag & drop based ondropzone.js;
- Image uploader integrated withtinymce 4.2 andCKEditor 4.5
- Run :
composer require romano83/cakephp3-media- Import The file
config\schema\medias.sqlin your database
In yourconfig\bootstrap.php file, add this line
Plugin::load('Media', ['bootstrap' =>false,'routes' =>true]);
By default, the plugin is blocked for everyone. To set proper permissions, you can implementcanUploadMedia() method in yourYourApp\AppController.For exemple :
publicfunctioncanUploadMedias($model,$id){if($model ==='YourApp\Model\Table\UsersTable' &&$id ==$this->Auth->user('id')){returntrue;// Everyone can upload medias for their own records}return$this->Auth->user('role') =='admin';// Admins have all rights}
To use this plugin, you must load theMediaBehavior in your tables. Form instance, if you want to manage medias for your posts :
<?phpnamespaceMyApp\Model\Table;useCake\ORM\Table;class PostsTableextends Table{publicfunctioninitialize(array$config){$this->addBehavior('Media.Media', ['path' =>'img/upload/%y/%m/%f',// default upload path relative to webroot folder (see below for path parameters)'extensions' => ['jpg','png'],// array of authorized extensions (lowercase)'limit' =>0,// limit number of upload file. Default: 0 (no limit)'max_width' =>0,// maximum authorized width for uploaded pictures. Default: 0 (no limitation)'max_height' =>0,// maximum authorized height for uploaded pictures. Default: 0 (no limitation)'size' =>0// maximum autorized size for uploaded pictures (in kb). Default: 0 (no limitation)]);}}
For the path option, you have numerous parameters :
- %yYear
- %mMonth
- %fSluggified filename
- %idMedia Id
- %cidMedia Id /100
- %midMedia Id /1000
In order to add media upload and edit capabilities in your views, you can useMediaHelper.
To do so, add in yourAppController
<?phpnamespaceApp\Controller;class AppControllerextends Controller{public$helpers = ['Media.Media'];}
Or in yourAppView
<?phpnamespaceApp\View;class AppViewextends View{publicfunctioninitialize(){$this->loadHelper('Media.Media' );}}
For example, you can add an iframe to manage medias:
<?=$this->Media->iframe('Model','ID');?>
Or you can add text editor (tinymce for instance) inside form :
<?=$this->Form->create();?><?=$this->Media->tinymce($fieldname,'Model','Id', array$options);?><?=$this->Form->end();?>
This method take the samearray $options than nativeFormInput helper.
If you want to add thumb for your posts, you must addmedia_id field in your 'Model' database table.
In order to upload pictures, you should implementdraft system for your model.
- Add the ability to edit a media when clicked;
- Add resize, crop, flip and rotate functions;
- Finish unit test...
- You have find a bug ? You can open anissue
- Clearly describe the issue including steps to reproduce when it is a bug.
- Make sure you fill in the earliest version that you know has the issue.
- Screenshots and code exemple are welcome in the issues.
- You want to implement a new feature or fix a bug ? Please follow this guide :
- Your codemust follow theCoding Standard of CakePHP. Check thecakephp-codesniffer repository to setup the CakePHP standard.
- You mustadd Test Cases for your new feature. Test Cases ensure that the application will continue to working in the future.
- Your PR should be on the
devbranch.
- Grafikart for the first version of this plugin !
About
The aim of this plugin is to give you the ability to create and associate any kind of medias in your application.
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Contributors2
Uh oh!
There was an error while loading.Please reload this page.