1
訪問`$ APP-> PARAMS [ 'uploadPath']
我創造如何配置和`在Yii2
namespace common\components; use yii\base\BootstrapInterface; class Bootstrap implements BootstrapInterface { public function bootstrap($app) { // Here you can refer to Application object through $app variable $app->params['uploadPath'] = $app->basePath . '/uploads/'; $app->params['uploadUrl'] => $app->urlManager->baseUrl . '/uploads/'; } }
2.
'bootstrap' => [
...
'common\components\Bootstrap',
];
如何訪問$app->params['uploadPath']
在我的控制器和視圖。 在此先感謝。
我曾經使用過這樣的Yii :: $ app-> params ['uploadPath'];但它不適合我。這是我已經實現的BootstrapInterface的問題,或者我喜歡Yii :: $ app-> params ['uploadPath']; intsead \ Yii :: $ app-> params ['uploadPath']; – Ganesh
將它包含在應用程序配置的引導區中:實際上它在哪裏?我已經在common/config/main-local.php中做過 – Ganesh
如果你在類中加了'Yii',否則它是'Yii',否則它就是'Yii'。只需在配置中添加'uploadPath',而不是引導此值。 – Bizley