- @web and @webroot aliases unavailable during application initialisation #929
- Comments
- Footer
- migrate: Invalid path alias: @infoweb/cms/mail #50
- Comments
- Footer
- i am using this widget, in windows OS its fine, linux error shown #9
- Comments
- Yii 2, псевдонимы пути для приложений basic и advanced
- Как создать/установить псевдоним (алиас) пути в Yii 2
- Как получить псевдоним (алиас) пути в Yii 2
- Дополнительно о псевдонимах путей в Yii 2
- Имя псевдонима
- Псевдонимы расширений
- Псевдонимы (алиасы) путей в Yii 2 basic приложении
- Псевдонимы (алиасы) путей в Yii 2 advanced приложении
@web and @webroot aliases unavailable during application initialisation #929
Comments
Its obvious that those are set after the Request component is created, but sometimes it’s important to have those in earlier stages like in themes exaple
The text was updated successfully, but these errors were encountered:
Unless these aliases are used BEFORE the request component is created, the configuration like you show above won’t cause problem. Do you have such an example that would indeed cause problem?
i’ve checked it again with fresh install of basic app with the following congfig
and again there was exception
exception ‘yii\base\InvalidParamException’ with message ‘Invalid path alias: @webroot/themes/test’ in /home/andrey/Projects/test.loc/src/vendor/yiisoft/yii2/yii/BaseYii.php:192 Stack trace: #0
So I see the reason is that we provide View component configuration on registerCoreComponents() in application constructor, while at this point the request component has not been initialized yet
@web and @webroot are set in \yii\web\Application::handleRequest(). And their values are made by request component (if I am not wrong).
So it is not possible to use some aliases in config file. How to resolve the issue?
So it is not possible to use some aliases in config file. How to resolve the issue?
@klimov-paul. I think It is needed to decide for what @web and @webroot needed. Is there any classification of existing aliases? Maybe some of them duplicate others. We can sweep them out right now.
I think It is needed to decide for what @web and @webroot needed.
What do you mean? ‘webroot’ points to the directory of the web application entry script, ‘web’ is an application base URL.
@egorpromo As I said, this is not an issue unless the application component runs BEFORE request component is loaded, which is very rare. I’m letting this issue open because @anfrantic gives an app config that may cause this issue, but it still needs to be verified.
@anfrantic Turn off debug and you see all correct. Debug uses ‘view’ module. This information you can see in stack trace. But don’t forget to turn debug on when you correct debug files!
Issue confirmed. This does not work well together with debug module as it is in preload section.
Also in my case errorHandler seems to have problems rendering the pretty page. Will look into this further.
I’ve tried to figure out some elegant solution for cases when we could use those aliases (as core provided) in preloaded components, so maybe we should declare init() method in the request component where those two are set and preload it in web\Application just like we preload the log component in base\Application?
I experience a similar issue, I am new to yii2, but i want to define aliases in my frontend/config/main.php
return [
‘id’ => ‘app-frontend’,
‘basePath’ => dirname(DIR),
‘bootstrap’ => [‘log’],
‘controllerNamespace’ => ‘frontend\controllers’,
‘name’ => ‘Hudson View’,
‘components’ => [
‘user’ => [
‘identityClass’ => ‘common\models\User’,
‘enableAutoLogin’ => true,
],
‘log’ => [
‘traceLevel’ => YII_DEBUG ? 3 : 0,
‘targets’ => [
[
‘class’ => ‘yii\log\FileTarget’,
‘levels’ => [‘error’, ‘warning’],
],
],
],
‘errorHandler’ => [
‘errorAction’ => ‘site/error’,
],
‘urlManager’ => [
‘enablePrettyUrl’ => true,
‘showScriptName’ => false,
],
‘assetManager’ => [
‘bundles’ => [
‘yii\bootstrap\BootstrapAsset’ => [
‘css’ => [],
]
],
]
],
‘params’ => $params,
‘aliases’ => [
‘@frontpage-photos’ => ‘@webroot/images/frontpage-photo’,
],
];
But it throws an exception:
Invalid Parameter – yii\base\InvalidParamException
Invalid path alias: @webroot/images/frontpage-photo
I dont think i have registered any special views or anything .. Is it not possible to reference @webroot in ‘aliases’ section of config?
please open a new issue, this one is from pre-alpha.
Footer
© 2023 GitHub, Inc.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
migrate: Invalid path alias: @infoweb/cms/mail #50
Comments
I followed your instructions, but I can’t migrate:
./yii migrate/up
PHP Deprecated: Comments starting with ‘#’ are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0
Exception ‘yii\base\InvalidParamException’ with message ‘Invalid path alias: @infoweb/cms/mail’
The text was updated successfully, but these errors were encountered:
Can you try running composer update again, and check for errors.
Exception ‘yii\base\InvalidParamException’ with message ‘Invalid path alias: @infoweb/cms/mail’
The path alias should be @infoweb/email, check your log files, in what file and which line are you getting this error?
Just followed the instructions from readme.md
‘viewPath’ => ‘@infoweb/cms/mail’,
But changed to @infoweb/email
Anyhow after composer update got this
Exception ‘yii\base\InvalidParamException’ with message ‘Invalid path alias: @in foweb/email’
Stack trace:
#0 /var/www/food/vendor/yiisoft/yii2/mail/BaseMailer.php(364): yii\BaseYii::getA lias(‘@infoweb/email’)
#1 /var/www/food/vendor/yiisoft/yii2/base/Component.php(169): yii\mail\BaseMaile r->setViewPath(‘@infoweb/email’)
#2 /var/www/food/vendor/yiisoft/yii2/BaseYii.php(518): yii\base\Component->__set (‘viewPath’, ‘@infoweb/email’)
#3 /var/www/food/vendor/yiisoft/yii2/base/Object.php(105): yii\BaseYii::configur e(Object(yii\swiftmailer\Mailer), Array)
#4 [internal function]: yii\base\Object->__construct(Array)
#5 /var/www/food/vendor/yiisoft/yii2/di/Container.php(372): ReflectionClass->new InstanceArgs(Array)
#6 /var/www/food/vendor/yiisoft/yii2/di/Container.php(151): yii\di\Container->bu ild(‘yii\swiftmailer. ‘, Array, Array)
#7 /var/www/food/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get(‘yi i\swiftmailer. ‘, Array, Array)
#8 /var/www/food/vendor/yiisoft/yii2/di/ServiceLocator.php(133): yii\BaseYii::cr eateObject(Array)
#9 /var/www/food/vendor/yiisoft/yii2/di/Instance.php(152): yii\di\ServiceLocator ->get(‘mailer’)
#10 /var/www/food/vendor/yiisoft/yii2/di/Instance.php(128): yii\di\Instance->get (NULL)
#11 /var/www/food/vendor/yiisoft/yii2/log/EmailTarget.php(70): yii\di\Instance:: ensure(‘mailer’, ‘yii\mail\Mailer. ‘)
#12 /var/www/food/vendor/yiisoft/yii2/base/Object.php(107): yii\log\EmailTarget- >init()
#13 [internal function]: yii\base\Object->_construct(Array)
#14 /var/www/food/vendor/yiisoft/yii2/di/Container.php(372): ReflectionClass->ne wInstanceArgs(Array)
#15 /var/www/food/vendor/yiisoft/yii2/di/Container.php(151): yii\di\Container->b uild(‘yii\log\EmailTa. ‘, Array, Array)
#16 /var/www/food/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get(‘y ii\log\EmailTa. ‘, Array, Array)
#17 /var/www/food/vendor/yiisoft/yii2/log/Dispatcher.php(101): yii\BaseYii::crea teObject(Array)
#18 /var/www/food/vendor/yiisoft/yii2/base/Object.php(107): yii\log\Dispatcher-> init()
#19 /var/www/food/vendor/yiisoft/yii2/log/Dispatcher.php(89): yii\base\Object-> _construct(Array)
#20 [internal function]: yii\log\Dispatcher->__construct(Array)
#21 /var/www/food/vendor/yiisoft/yii2/di/Container.php(372): ReflectionClass->ne wInstanceArgs(Array)
#22 /var/www/food/vendor/yiisoft/yii2/di/Container.php(151): yii\di\Container->b uild(‘yii\log\Dispatc. ‘, Array, Array)
#23 /var/www/food/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get(‘y ii\log\Dispatc. ‘, Array, Array)
#24 /var/www/food/vendor/yiisoft/yii2/di/ServiceLocator.php(133): yii\BaseYii::c reateObject(Array)
#25 /var/www/food/vendor/yiisoft/yii2/base/Application.php(302): yii\di\ServiceL ocator->get(‘log’)
#26 /var/www/food/vendor/yiisoft/yii2/base/Application.php(267): yii\base\Applic ation->bootstrap()
#27 /var/www/food/vendor/yiisoft/yii2/console/Application.php(114): yii\base\App lication->init()
#28 /var/www/food/vendor/yiisoft/yii2/base/Object.php(107): yii\console\Applicat ion->init()
#29 /var/www/food/vendor/yiisoft/yii2/base/Application.php(206): yii\base\Object ->__construct(Array)
#30 /var/www/food/vendor/yiisoft/yii2/console/Application.php(79): yii\base\Appl ication->__construct(Array)
#31 /var/www/food/yii(30): yii\console\Application->__construct(Array)
#32
PHP Notice: Trying to get property of non-object in /var/www/food/vendor/yiisof t/yii2/log/Dispatcher.php on line 181
PHP Notice: Trying to get property of non-object in /var/www/food/vendor/yiisof t/yii2/log/Dispatcher.php on line 181
PHP Notice: Trying to get property of non-object in /var/www/food/vendor/yiisof t/yii2/log/Dispatcher.php on line 181
PHP Notice: Trying to get property of non-object in /var/www/food/vendor/yiisof t/yii2/log/Dispatcher.php on line 181
PHP Notice: Trying to get property of non-object in /var/www/food/vendor/yiisof t/yii2/log/Dispatcher.php on line 181
PHP Notice: Trying to get property of non-object in /var/www/food/vendor/yiisof t/yii2/log/Dispatcher.php on line 181
I still think that you used a path alias that is not correct:
‘yii\base\InvalidParamException’ with message ‘Invalid path alias: @in foweb/email’
There seems to be a space in your alias
Footer
© 2023 GitHub, Inc.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
i am using this widget, in windows OS its fine, linux error shown #9
Comments
exception ‘yii\base\InvalidParamException’ with message ‘Invalid path alias: @mihaildev/ckeditor/editor’ in /usr/share/nginx/www/urge/vendor/yiisoft/yii2/BaseYii.php:152 Stack trace: #0 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/web/AssetBundle.php(128): yii\BaseYii::getAlias() #1 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/Object.php(107): yii\web\AssetBundle->init() #2 (): yii\base\Object->__construct() #3 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/di/Container.php(362): ReflectionClass->newInstanceArgs() #4 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/di/Container.php(147): yii\di\Container->build() #5 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get() #6 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/web/AssetManager.php(219): yii\BaseYii::createObject() #7 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/web/AssetManager.php(192): yii\web\AssetManager->loadBundle() #8 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/web/View.php(284): yii\web\AssetManager->getBundle() #9 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/web/AssetBundle.php(118): yii\web\View->registerAssetBundle() #10 /usr/share/nginx/www/urge/vendor/mihaildev/yii2-ckeditor/CKEditor.php(123): yii\web\AssetBundle::register() #11 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/Widget.php(96): mihaildev\ckeditor\CKEditor->run() #12 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/widgets/ActiveField.php(717): yii\base\Widget::widget() #13 /usr/share/nginx/www/urge/vendor/kartik-v/yii2-widget-activeform/ActiveField.php(522): yii\widgets\ActiveField->widget() #14 /usr/share/nginx/www/urge/backend/views/setting/_form.php(45): kartik\form\ActiveField->widget() #15 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/View.php(325): include() #16 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/View.php(247): yii\base\View->renderPhpFile() #17 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/View.php(149): yii\base\View->renderFile() #18 /usr/share/nginx/www/urge/backend/views/setting/update.php(21): yii\base\View->render() #19 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/View.php(325): include() #20 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/View.php(247): yii\base\View->renderPhpFile() #21 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/View.php(149): yii\base\View->renderFile() #22 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/Controller.php(367): yii\base\View->render() #23 /usr/share/nginx/www/urge/backend/controllers/SettingController.php(125): yii\base\Controller->render() #24 (): backend\controllers\SettingController->actionUpdate() #25 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array() #26 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams() #27 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction() #28 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module->runAction() #29 /usr/share/nginx/www/urge/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest() #30 /usr/share/nginx/www/urge/backend/web/index.php(18): yii\base\Application->run() #31
The text was updated successfully, but these errors were encountered:
Yii 2, псевдонимы пути для приложений basic и advanced
Псевдонимы (алиасы) предназначены для обозначения путей к папкам, файлам или URL. Псевдонимы помогают избежать использования абсолютных путей или URL в коде. Чтобы не путать псевдоним с обычным путем к папке, файлу или URL, он должен начинаться с @ . В yii есть заранее заданные псевдонимы (алиасы), например @yii , @app , но так же есть возможность задать свои псевдонимы.
Как создать/установить псевдоним (алиас) пути в Yii 2
Для того чтобы создать псевдоним (алиас) пути используется метод Yii::setAlias() :
Псевдонимы путей в yii2 можно задать в файле конфигураций приложения с помощью свойства aliases , пример:
Как получить псевдоним (алиас) пути в Yii 2
Для того чтобы получить псевдоним пути в yii2 используеться метод Yii::getAlias() :
Дополнительно о псевдонимах путей в Yii 2
Имя псевдонима
Имя псевдонима может содержать /, при этом метод Yii::getAlias() определит какая часть является именем псевдонима, а какая добавочным путем, например:
Если бы в строке 2 небыл определен алиас @test/val , то строка 4 вернула бы /path/to/test/val/index.php
Псевдонимы расширений
При установке расширения с помощью composer, для него автоматически задается псевдоним (путь к корневой директории расширения). Например при установке imperavi redactor (vova07/yii2-imperavi-widget), вам будет доступен псевдоним пути @vova07/imperavi ( @vendor/vova07/yii2-imperavi-widget/src )
Псевдонимы (алиасы) путей в Yii 2 basic приложении
Список основных, заранее заданных псевдонимов (алиасов) путей в yii2 basic:
- @app : Корневой каталог приложения
- @vendor : Папка vendor, под @app
- @runtime : Путь к временным файлам приложения runtime/cache
- @web : Базовый URL приложения
- @webroot : Webroot приложения
- @tests : Каталог с тестами приложения
Псевдонимы (алиасы) путей в Yii 2 advanced приложении
Список основных, заранее заданных псевдонимов (алиасов) путей в yii2 advanced:
- @app : Корневой каталог приложения
- @vendor : Папка vendor, под @app
- @runtime : Путь к временным файлам приложения runtime/cache
- @web : Базовый URL приложения
- @webroot : Каталог с тестами приложения
- @tests : Каталог с тестами приложения
- @common : Псевдоним (алиас) для common (общей) директории под @app
- @frontend : Псевдоним (алиас) для frontend директории, под @app
- @backend : Псевдоним (алиас) для backend директории, под @app
- @console : Псевдоним (алиас) для console директории, под @app
Если у вас есть вопросы или предложения по улучшению кода описанного в статье пишите в комментариях.
Я всегда открыт к конструктивному диалогу