成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專(zhuān)欄INFORMATION COLUMN

laravel5.1 -- Integrate FileManager and CKeditor i

VPointer / 793人閱讀

摘要:中文名叫文件管理器,也叫文件瀏覽器,它給我們提供了一個(gè)可視化的界面來(lái)管理文件和文件夾。利用,我們可以對(duì)文件進(jìn)行瀏覽增加打印修改文件屬性重命名搜索等等一大堆非常有用的操作。相信朋友們都非常熟悉了,它是一種富文本編輯器,不再贅述。

FileManager中文名叫文件管理器,也叫文件瀏覽器,它給我們提供了一個(gè)可視化的界面來(lái)管理文件和文件夾。利用FileManager,我們可以對(duì)文件進(jìn)行瀏覽、增加、打印、修改(文件屬性)、重命名、搜索等等一大堆非常有用的操作。
CKeditor相信朋友們都非常熟悉了,它是一種富文本編輯器,不再贅述。
現(xiàn)在我們來(lái)演示如何將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,
發(fā)布
$ php artisan vendor:publish --provider="BestmomoFilemanagerFilemanagerServiceProvider"
User模型中添加2個(gè)權(quán)限方法
/**
* 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來(lái)配置引入的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

到了這里,整個(gè)FileManager就整合到了laravel中,但我在實(shí)際運(yùn)行中,報(bào)了一個(gè)小錯(cuò)誤:
call_user_func_array() expects parameter 1 to be a valid callback, class "KbwebsMultiAuthGuard" does not have a method "accessMediasAll"
說(shuō)是"KbwebsMultiAuthGuard"沒(méi)有accessMediasAll方法。
原因是我在laravel5.1中做了多用戶(hù)驗(yàn)證功能,安裝了"KbwebsMultiAuthGuard"插件,所以在所有要獲取User模型的時(shí)候都要加上一個(gè)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界面

上面的代碼更新完成后,已經(jīng)可以看到FileManager的文件管理界面

引入CKeditor

下載CKeditor并解壓到public文件夾后,在頁(yè)面中引入ckeditor/ckeditor.js



CKEDITOR.replace( "summary");   

config["height"] = 400;        

CKEDITOR.replace( "content");

如果要實(shí)現(xiàn)ckeditorFileManager中導(dǎo)入文件,則需要修改filebrowserBrowseUrl選項(xiàng)

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

    config["height"] = 400;        

    CKEDITOR.replace( "content", config);

ckeditor上傳圖片的效果圖

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/22642.html

相關(guān)文章

  • CKEditor4.7怎樣實(shí)現(xiàn)上傳圖片,瀏覽服務(wù)器(無(wú)需ckfinder),nodejs圖片管理,字

    首先是下載CKEditor,下載地址:http://ckeditor.com/download 選擇里面的Customize自定義,如圖 showImg(https://segmentfault.com/img/bVRlFy?w=1406&h=858); 然后進(jìn)入配置界面,第一個(gè)choose preset一般就選standard標(biāo)準(zhǔn)的 第二個(gè)需要添加兩個(gè)東西進(jìn)去 第一個(gè)是Justify showI...

    mengera88 評(píng)論0 收藏0
  • CKEditor4.7怎樣實(shí)現(xiàn)上傳圖片,瀏覽服務(wù)器(無(wú)需ckfinder),nodejs圖片管理,字

    首先是下載CKEditor,下載地址:http://ckeditor.com/download 選擇里面的Customize自定義,如圖 showImg(https://segmentfault.com/img/bVRlFy?w=1406&h=858); 然后進(jìn)入配置界面,第一個(gè)choose preset一般就選standard標(biāo)準(zhǔn)的 第二個(gè)需要添加兩個(gè)東西進(jìn)去 第一個(gè)是Justify showI...

    lowett 評(píng)論0 收藏0
  • ??ASP.NET 使用 Dispose 釋放資源的四種方法?

    Dispose 和 Finalize 是運(yùn)行的 .NET 和 .NET Core 應(yīng)用程序釋放占用的資源的兩種方法。通常,如果應(yīng)用程序中有非托管資源,應(yīng)該顯式地釋放這些資源占用的資源。由于 Finalize 的非確定性,以及在性能方面的成本很高,因此 Dispose 方法的使用頻率遠(yuǎn)高于 Finalize。其實(shí),我們可以在一個(gè)實(shí)現(xiàn)了 IDisposable 接口的類(lèi)型上使用 Dispose 方法。...

    bovenson 評(píng)論0 收藏0
  • Django搭建個(gè)人博客:用django-mptt實(shí)現(xiàn)多級(jí)評(píng)論功能

    摘要:現(xiàn)在我們的博客已經(jīng)具有評(píng)論功能了。處理請(qǐng)求處理其他請(qǐng)求僅接受請(qǐng)求。前面寫(xiě)視圖的時(shí)候,二級(jí)評(píng)論提交成功后會(huì)返回,回調(diào)函數(shù)接收到這個(gè)信號(hào)后,就會(huì)調(diào)用方法,刷新當(dāng)前的父頁(yè)面即文章所在的頁(yè)面,實(shí)現(xiàn)了數(shù)據(jù)的更新。 現(xiàn)在我們的博客已經(jīng)具有評(píng)論功能了。隨著文章的評(píng)論者越來(lái)越多,有的時(shí)候評(píng)論者之間也需要交流,甚至部分評(píng)論還能合并成一個(gè)小的整體。因此最好是有某種方法可以將相關(guān)的評(píng)論聚集到一起,這時(shí)候多級(jí)...

    adie 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<