doufu9836 2013-10-05 00:16
浏览 96

Symfony2 KendoUI实现

This is more a question of how to best import/integrate a JS library to use within a Symfony2 application ... I just happen to be using KendoUI as the test library.

I've already generated a bundle that converts and maps my database - including all associations.

 $ php app/console generate:bundle namespace=DB/DBImportBundle

this includes some other cli statements for all the mapping and converting (with annotations) ... we can assume that is all working fine. I have generated CRUD for all the tables that I need.

I will now want to make the KendoUI library available to all controllers ... and my first inclination was to ...

$ php app/console generate:bundle namespace=Kendo/KendoBundle

Next step was to move the Kendo's css/js files into the KendoBundle/Resources/public folders ... and then to declare the namespace in all the controllers where I intended to use it ...

use Kendo\KendoBundle;

This still leaves the question of where the php wrappers that come with the library should be placed. The tutorials in the Kendo docs only walk you through a straightforward static implementation of the library.

My question is more general in terms of how properly to integrate different libraries into a Symfony2 application.

  • 写回答

2条回答 默认 最新

  • douerlin4366 2016-01-27 03:46
    关注

    I put them in the lib folder on the main project path. Inside that lib folder I put a folder called Kendoui, which has the kendo files in it (like DataSourceResult.php, FileBrowser.php, ImageBrowser.php, Kendo (folder), and SchedulerDataSourceResult.php.

    Then in your composer.json file, change autoload to look like below. Notice the classmap reference for lib, this will tell it to look there for the library.

    "autoload": {
            "psr-4": {
                "": "src/"
            },
            "classmap": [
                "app/AppKernel.php",
                "app/AppCache.php",
                "lib"
            ]
        },
    

    Next run composer update and/or composer dump-autoload so that it remakes the autoload files. Now you can reference KendoUI for something like a datepicker control like this.

    /**
     * @Route("/homepage", name="home")
     */
    public function home(Request $request)
    {
    
        $datePicker = new \Kendo\UI\DatePicker('datepicker');
    
        return new Response($datePicker->render());
    
    }
    

    Word of caution, I did notice composer give a warning for me that said...

    Warning: Ambiguous class resolution, "Kendo\Dataviz\UI\DiagramConnectionDefaultsEndCap" was found in both "/home/distribution/public_html/distribution.tech/lib/Kendoui/Kendo/Dataviz/UI/DiagramConnectionDefaultsEndCap.stroke.php" and "/home/distribution/public_html/distribution.tech/lib/Kendoui/Kendo/Dataviz/UI/DiagramConnectionDefaultsEndCap.php", the first will be used.
    

    However everything still seemed to work fine, but if anyone knows how to resolve this warning let me know and I'll revise my answer.

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比