Management, deployment, and use of Assets resources in the Yii Framework
Assets (js, css, images, etc.) are generally released in the following ways, which must be used flexibly in practice:
1. save a single file directly under the Web Directory (for example, put pager.css in the css directory separately ). Advantages: high efficiency and relatively independent. Disadvantages: if the project is large and there may be many resource files, the management and usage of the project will be complicated. Reuse is also relatively complex. pay special attention to the storage location and corresponding URL of resource files when reusing them.
2. Save the code segment with it in the file under the Web Directory (for example, place pager's CSS in a main.css file and stay with other CSS files ). Advantages: high efficiency. Disadvantage: if the project is large, the resource file may be complex and difficult to maintain. In addition, reuse is more complex because the corresponding resource code snippets need to be extracted.
3. put the php code together and publish (copy) the php code to the web Directory through assetManager when calling the php code. Advantages: Easy to reuse (for example, if you use the yii built-in CLinkPager, you do not need to consider how to place its js/css ). Disadvantage: low efficiency.
Generally, if your code is not intended to be reused in other projects, consider 1 or 2. Method 2 is applicable to small projects. Method 3 is mainly used for components you want to reuse, such as google map.