Giter Site home page Giter Site logo

yii-admin's People

Contributors

armo1127 avatar mro1127 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

yii-admin's Issues

前端资源方案,使用asset

YII2的前端资源用asset来管理,一开始接触觉得略麻烦,渐渐感觉还好,配合bower管理各种前端的组件,一下是本系统的前端资源方案

  1. 能用bower管理的包,都用bower管理,方便维护
  2. asset资源包配置
    资源包都配置在 common\config\asset.php,方便查找,也可以取别名(键名就是别名)比如Adminlte,JQuery),这样引入时也不用填太长。分两种情况:
  • [ 写了Asset类文件 ] 可以不配置(不推荐),如果配置了,可以直接用键名引入该asset,配置如下
        'Adminlte' => [
            'class' => 'common\assets\AdminlteAsset'
        ]
  • [ 没写Asset类文件 ] 每个包都要写个asset类文件也很麻烦,特别是只引入一个文件的包,这种情况可以不写asset包,直接在asset.php中配置该包,实际上他也是个asset类,class要设为 'yii\web\AssetBundle',如下
   'BootstrapTable'=> [
            'class' => 'yii\web\AssetBundle',
            'sourcePath' => '@bower/bootstrap-table/dist',
            'css' => ['bootstrap-table.min.css'],
            'js' => ['bootstrap-table.min.js'],
            'depends' => ['Bootstrap']
        ]
  1. asset的引入
  • 类似adminlte、jq、boostrap这些几乎每个页面都要用的,直接列入AppAsset的depends,每个页面都加载。
  • 类似BootstrapTable不是每个页面都用,可以在视图上引入,代码如($this是视图类,view)
$this->registerAssetBundle('BootstrapTable');
  1. 如果某个页面需要单独引入css或js文件,如下
$this->registerJsFile('@web/js/app.js');
$this->registerCssFile('@web/css/app.css');

为何用bower,而不用官网推荐的方式

官方推荐方式是:
安装 composer插件 "fxp/composer-asset-plugin:^1.4.1"
将bower包写进composer.json,这样在composer update时就可以安装bower依赖了
官方文档
中文文档(比较不全)

但在安装admin-lte过程中,其中一个包就除了问题,alphashack/eve,报了这个包没有找到bower.json,
而bower安装正常,猜测是 "fxp/composer-asset-plugin:^1.4.1"有问题
而直接使用bower,也并不麻烦,只要安装了bower,前端资源包放在bower.json管理即可。
为了避免未知的麻烦,直接使用bower。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.