[Yii2] Composer bower-asset 更新失敗解法

遇到的Composer update問題: yiisoft/yii2 2.*.* requires bower-asset/jquery *.*.*@stable | … -> no matching package found. Yii官網解:composer global require fxp/composer-asset-plugin 本篇是針對不使用Plugin提供解法。 原因: bower-asset在Packagist已經是Virtual Package,以下為bower因果: Update: bower 在 0.9.0 版以前可以使用 component.json,但是為了避免跟其他工具命名衝突,故 0.9.0 以後版本請改為 bower.json bower 是 Twitter 團隊開發的一套網頁工具,用來管理或安裝 Web 開發所需要的 Package,像是 CSS 和 […]

[Yii2] 佈署子目錄網址架構(Route SubDirectory) – 設定 $request->baseUrl、修正Url與PrettyUrl

Yii2部屬上,如果不是在Domain根目錄,要部屬Yii2恐造成Base Url錯亂及PrettyUrl後的Route吃不進Yii。 例如,在Nginx location目錄名與實體uri(Sub document root in location)不一樣下,預設的Yii其Base Url會以uri為主而非Nginx location目錄名,另外PrettyUrl因為無法正確比對REQUEST_URI導致Route無法解析。 基本影響層級,Url可能是取自DOCUMENT_URI \yii\helpers\Url::to([‘/’]); \yii\helpers\Url::home(); 【解決方法】: 在Yii2 config -> request component -> baseUrl 設定基礎目錄(同Nginx location目錄名),以讓Yii依此套用全部基礎Url,也才能依此路徑去比對REQUEST_URI取得Route。 $config = [ ‘components’ => [ ‘request’ => [ ‘cookieValidationKey’ => ”, ‘baseUrl’ => ‘/subdir’ ], ] […]