资讯专栏INFORMATION COLUMN

laravel5.1 -- Integrate FileManager and CKeditor i

VPointer / 567人阅读

摘要:中文名叫文件管理器,也叫文件浏览器,它给我们提供了一个可视化的界面来管理文件和文件夹。利用,我们可以对文件进行浏览增加打印修改文件属性重命名搜索等等一大堆非常有用的操作。相信朋友们都非常熟悉了,它是一种富文本编辑器,不再赘述。

FileManager中文名叫文件管理器,也叫文件浏览器,它给我们提供了一个可视化的界面来管理文件和文件夹。利用FileManager,我们可以对文件进行浏览、增加、打印、修改(文件属性)、重命名、搜索等等一大堆非常有用的操作。
CKeditor相信朋友们都非常熟悉了,它是一种富文本编辑器,不再赘述。
现在我们来演示如何将FileManagerCKeditor整合到laravel中去。

Install FileManager Require filemanater

filemanager加入到composer.json中我们用bestmomo/filemanager

require : {
        "laravel/framework": "5.2.*",
        "bestmomo/filemanager": "1.1.*"
    }
Update Composer
$ composer update

更新完成后,将service provider加入到config/app.php

 /**
 * App/Config/App.php
 */

BestmomoFilemanagerFilemanagerServiceProvider::class,
发布
$ php artisan vendor:publish --provider="BestmomoFilemanagerFilemanagerServiceProvider"
User模型中添加2个权限方法
/**
* App/Http/Models/User.php
*/

    /**
    * Check media all access
    *
    * @return bool
    */
    public function accessMediasAll(){
    
        return $this->role->slug == "admin";
    }

    /**
     * Check media access one folder
     *
     * @return bool
     */
    public function accessMediasFolder()
    {
        return $this->role->slug != "user";
    }
添加路由与方法

模型配置完了,就需要添加路由和控制器的方法了

路由
// route.php

Route::get("medias", ["as"=>"medias", "uses"=>"AdminAdminController@filemanager"]);
配置文件

新建配置文件medias.php来配置引入的filemanager目录

// Config/medias.php

 "filemanager/index.html",
    "url-files" =>"/public/filemanager/userfiles/"

];
方法

在控制器AdminController中我们添加filemanager方法

    /**
    * Show the media panel
    *
    * @return Response
    */
    public function filemanager(){
        $url = config("medias.url") . "?langCode=" . config("app.locale");

        return view("backend.filemanager")->with(compact("url"));
    }
filemanager.blade.php模板
@extends("backend.layout.master")

@section("head")

    

@stop

@section("main")

    @include("backend.partials.entete", ["heading" => trans("backend/medias.dashboard"), "operation"=>"", "symbol" => "file-image-o", "superior" => trans("backend/medias.medias")])

    
@stop

到了这里,整个FileManager就整合到了laravel中,但我在实际运行中,报了一个小错误:
call_user_func_array() expects parameter 1 to be a valid callback, class "KbwebsMultiAuthGuard" does not have a method "accessMediasAll"
说是"KbwebsMultiAuthGuard"没有accessMediasAll方法。
原因是我在laravel5.1中做了多用户验证功能,安装了"KbwebsMultiAuthGuard"插件,所以在所有要获取User模型的时候都要加上一个user(), 比如 Auth::user->user(), auth()->user()->user()

解决方法:

找到有accessMediaAllaccessMediasFolder的文件/filemanager/connectors/php/default.config.php


 *  @copyright  Authors
 */

// Laravel init
require getcwd() . "/../../../../bootstrap/autoload.php";
$app = require_once getcwd() . "/../../../../bootstrap/app.php";

$kernel = $app->make("IlluminateContractsHttpKernel");

$response = $kernel->handle(
  $request = IlluminateHttpRequest::capture()
);

$id = $app["encrypter"]->decrypt($_COOKIE[$app["config"]["session.cookie"]]);
$app["session"]->driver()->setId($id);
$app["session"]->driver()->start();

// Folder path
$folderPath = config("filemanager.folder_path");   

// Check if user in authentified
if(!$app["auth"]->check()) 
{
  $laravelAuth = false;
} 
else 
{ //print_r($app["auth"]->user()->user()->accessMediasAll());exit;
  // Check if user has all access
  if($app["auth"]->user()->accessMediasAll())
  {
    $laravelAuth = true; 
  } 
  elseif(method_exists($app["auth"]->user(), "accessMediasFolder"))
  {  
    // Check if user has access to one folder
    if($app["auth"]->user()->accessMediasFolder())
    { 
      // Folder name with user id
      $folderPath .= "user" . $app["auth"]->id();
      $laravelAuth = true;  
    } 
    else
    {
      $laravelAuth = false;
    }    
  }
  else
  {
    $laravelAuth = false;
  } 
}

分别将
$app["auth"]->user()->accessMediasAll()
$app["auth"]->user()
$app["auth"]->user()->accessMediasFolder()
$app["auth"]->id()
改为
$app["auth"]->user()->user()->accessMediasAll()
$app["auth"]->user()->user()
$app["auth"]->user()->user()->accessMediasFolder()
$app["auth"]->user()->id()

FileManager界面

上面的代码更新完成后,已经可以看到FileManager的文件管理界面

引入CKeditor

下载CKeditor并解压到public文件夹后,在页面中引入ckeditor/ckeditor.js



CKEDITOR.replace( "summary");   

config["height"] = 400;        

CKEDITOR.replace( "content");

如果要实现ckeditorFileManager中导入文件,则需要修改filebrowserBrowseUrl选项

    var config = {
    filebrowserBrowseUrl : "/filemanager/index.html"
    }
    
    CKEDITOR.replace( "summary", config);

    config["height"] = 400;        

    CKEDITOR.replace( "content", config);

ckeditor上传图片的效果图

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/22642.html

相关文章

  • CKEditor4.7怎样实现上传图片,浏览服务器(无需ckfinder),nodejs图片管理,字

    首先是下载CKEditor,下载地址:http://ckeditor.com/download 选择里面的Customize自定义,如图 showImg(https://segmentfault.com/img/bVRlFy?w=1406&h=858); 然后进入配置界面,第一个choose preset一般就选standard标准的 第二个需要添加两个东西进去 第一个是Justify showI...

    mengera88 评论0 收藏0
  • CKEditor4.7怎样实现上传图片,浏览服务器(无需ckfinder),nodejs图片管理,字

    首先是下载CKEditor,下载地址:http://ckeditor.com/download 选择里面的Customize自定义,如图 showImg(https://segmentfault.com/img/bVRlFy?w=1406&h=858); 然后进入配置界面,第一个choose preset一般就选standard标准的 第二个需要添加两个东西进去 第一个是Justify showI...

    lowett 评论0 收藏0
  • ​​ASP.NET 使用 Dispose 释放资源的四种方法​

    Dispose 和 Finalize 是运行的 .NET 和 .NET Core 应用程序释放占用的资源的两种方法。通常,如果应用程序中有非托管资源,应该显式地释放这些资源占用的资源。由于 Finalize 的非确定性,以及在性能方面的成本很高,因此 Dispose 方法的使用频率远高于 Finalize。其实,我们可以在一个实现了 IDisposable 接口的类型上使用 Dispose 方法。...

    bovenson 评论0 收藏0
  • Django搭建个人博客:用django-mptt实现多级评论功能

    摘要:现在我们的博客已经具有评论功能了。处理请求处理其他请求仅接受请求。前面写视图的时候,二级评论提交成功后会返回,回调函数接收到这个信号后,就会调用方法,刷新当前的父页面即文章所在的页面,实现了数据的更新。 现在我们的博客已经具有评论功能了。随着文章的评论者越来越多,有的时候评论者之间也需要交流,甚至部分评论还能合并成一个小的整体。因此最好是有某种方法可以将相关的评论聚集到一起,这时候多级...

    adie 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<