งานที่ทำใช้ jQuery plugin ที่จำกัดอยู่ที่ไม่เกินเวอร์ชั่น 2.1.3 เท่านั้น แต่ทุกครั้งที่ update yii โดยใช้คำสั่ง composer update มันจะเปลี่ยนเจคิวรี่เป็นตัว 2.1.4 ทุกครั้ง ต้องมาเปลี่ยนทุกครั้งเลย แก้ได้โดยไปสั่งใช้คอมโพสเซอร์โหลดตัวที่ต้องการมา
- แก้ composer.json เพิ่ม
composer.json 12345"require"
: {
...
"components/jquery"
:
"2.1.3"
...
},
- ไปใช้ command พิมพ์ composer update มันจะโหลดเจคิวรี่มาเก็บไว้ที่ \vendor\components\jquery
- สั่งให้ยีสองโหลด jquery ตัวนี้มาใช้โดยกำหนด
main.php 123456789101112131415...
'components'
=> [
...
'assetManager'
=> [
'bundles'
=> [
'yii\web\JqueryAsset'
=> [
'baseUrl'
=>
'@web'
,
'js'
=> [
'../../vendor/components/jquery/jquery.min.js'
,
],
'sourcePath'
=> null
],
],
],
...
yii จะเปลี่ยน link จาก
1 | < script src = "/YiiAdvanced/frontend/web/assets/41df07c8/jquery.js" ></ script > |
เป็น
1 | < script src = "/YiiAdvanced/frontend/web/../../vendor/components/jquery/jquery.min.js" ></ script > |
หลังจากนี้ถึงจะอัพเดทกี่ครั้ง jquery ก็จะยังเป็นตัวเดิมอยู่
About the author