<i id='qazED'><tr id='qazED'><dt id='qazED'><q id='qazED'><span id='qazED'><b id='qazED'><form id='qazED'><ins id='qazED'></ins><ul id='qazED'></ul><sub id='qazED'></sub></form><legend id='qazED'></legend><bdo id='qazED'><pre id='qazED'><center id='qazED'></center></pre></bdo></b><th id='qazED'></th></span></q></dt></tr></i><div id='qazED'><tfoot id='qazED'></tfoot><dl id='qazED'><fieldset id='qazED'></fieldset></dl></div>
    1. <tfoot id='qazED'></tfoot>

      <small id='qazED'></small><noframes id='qazED'>

        <legend id='qazED'><style id='qazED'><dir id='qazED'><q id='qazED'></q></dir></style></legend>
          <bdo id='qazED'></bdo><ul id='qazED'></ul>
      1. Yii2:注册资产包与注册外部 Js 文件

        Yii2: Registering Asset Bundle vs registering external Js file(Yii2:注册资产包与注册外部 Js 文件)
        • <small id='NdvPl'></small><noframes id='NdvPl'>

            <tbody id='NdvPl'></tbody>
          <i id='NdvPl'><tr id='NdvPl'><dt id='NdvPl'><q id='NdvPl'><span id='NdvPl'><b id='NdvPl'><form id='NdvPl'><ins id='NdvPl'></ins><ul id='NdvPl'></ul><sub id='NdvPl'></sub></form><legend id='NdvPl'></legend><bdo id='NdvPl'><pre id='NdvPl'><center id='NdvPl'></center></pre></bdo></b><th id='NdvPl'></th></span></q></dt></tr></i><div id='NdvPl'><tfoot id='NdvPl'></tfoot><dl id='NdvPl'><fieldset id='NdvPl'></fieldset></dl></div>
        • <tfoot id='NdvPl'></tfoot>

                <bdo id='NdvPl'></bdo><ul id='NdvPl'></ul>

                <legend id='NdvPl'><style id='NdvPl'><dir id='NdvPl'><q id='NdvPl'></q></dir></style></legend>

                1. 本文介绍了Yii2:注册资产包与注册外部 Js 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想知道按照文档中描述的过程注册 Asset Bundle 的好处,例如流程一在 AppAsset.php 中

                  Hi I wanted to know the advantage of registering Asset Bundle following the process described in the docs like Process one in AppAsset.php

                  public $js = [
                          'js/myjsfile.js'
                      ];
                  

                  然后在视图文件中添加命名空间如

                  then in the view file adding Namespace like

                  namespace appassets;
                  

                  然后添加像

                  use appassetsAppAsset;
                  AppAsset::register($this);
                  

                  如果我使用流程二

                  $this->registerJs('js/myjsfile.js', $this::POS_READY);
                  

                  它工作正常.那么我为什么要使用流程一.

                  it works fine. So why should I use Process One.

                  1. 对此的任何优势和原因将不胜感激.
                  2. 如果我按照流程一是否需要将所有js文件添加到AppAsset.php 单独.
                  1. Any advantage and reason for this will be greatly appreciated.
                  2. If I follow the process one Do I need to add all the js files in AppAsset.php individually.

                  谢谢.

                  推荐答案

                  使用 Asset Bundle 的主要原因之一是您的资产路径始终是正确的.考虑:

                  One of the main reasons for using an Asset Bundle is that your assets' paths will always be correct. Consider:

                  $this->registerJsFile('js/myjsfile.js', ['position'=>$this::POS_READY]);
                  

                  会产生类似的东西:

                  <script src="js/myjsfile.js"></script>
                  

                  这对于非 urlManager 启用的 url 非常有用,例如http://localhost/yiiproject/index.php?r=user/update&id=8 因为您的浏览器会在以下位置查找 js 文件:/yiiproject/js/myjsfile.js

                  Which works great for non urlManager enabled urls, e.g. http://localhost/yiiproject/index.php?r=user/update&id=8 because your browser looks for the js file at: /yiiproject/js/myjsfile.js

                  但是如果你启用了 urlManager,你的 url 将看起来像 http://localhost/yiiproject/user/update/8,这意味着你的浏览器会在以下位置寻找你的 js 文件:/yiiproject/user/update/8/js/myjsfile.js.

                  But if you enable urlManager, your url will look like http://localhost/yiiproject/user/update/8, which means your browser will look for your js file at: /yiiproject/user/update/8/js/myjsfile.js.

                  您可以使用以下方法解决此问题:

                  You could overcome this problem by using:

                  $this->registerJsFile(Yii::$app->request->baseUrl.'/js/myjsfile.js', ['position'=>$this::POS_READY]);
                  

                  但是 Asset Bundle 基本上可以为您做到这一点.

                  But the Asset Bundle basicly does that for you.

                  这篇关于Yii2:注册资产包与注册外部 Js 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Joomla 2.5 much faster than Joomla 1.5 Querywise(Joomla 2.5 比 Joomla 1.5 Querywise 快得多吗)
                  How to share Joomla login session from one joomla website to one ASP.Net MVC website(如何将 Joomla 登录会话从一个 joomla 网站共享到一个 ASP.Net MVC 网站)
                  htaccess redirect root to subdirectory but allow index.php in root AND query strings to function(htaccess 将根重定向到子目录,但允许根和查询字符串中的 index.php 起作用)
                  Joomla include database functions(Joomla 包含数据库功能)
                  nl2br() not working when displaying SQL results(显示 SQL 结果时 nl2br() 不起作用)
                  Joomla 2.5 JFactory::getSession(); seems to be caching in firefox(Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存)
                2. <legend id='Tjg3F'><style id='Tjg3F'><dir id='Tjg3F'><q id='Tjg3F'></q></dir></style></legend>

                    <i id='Tjg3F'><tr id='Tjg3F'><dt id='Tjg3F'><q id='Tjg3F'><span id='Tjg3F'><b id='Tjg3F'><form id='Tjg3F'><ins id='Tjg3F'></ins><ul id='Tjg3F'></ul><sub id='Tjg3F'></sub></form><legend id='Tjg3F'></legend><bdo id='Tjg3F'><pre id='Tjg3F'><center id='Tjg3F'></center></pre></bdo></b><th id='Tjg3F'></th></span></q></dt></tr></i><div id='Tjg3F'><tfoot id='Tjg3F'></tfoot><dl id='Tjg3F'><fieldset id='Tjg3F'></fieldset></dl></div>

                    <small id='Tjg3F'></small><noframes id='Tjg3F'>

                    <tfoot id='Tjg3F'></tfoot>
                        <bdo id='Tjg3F'></bdo><ul id='Tjg3F'></ul>
                              <tbody id='Tjg3F'></tbody>