New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-init component on fly #3436
Comments
The docs of
this is not the case atm. @qiangxue looks like a bug to me, right? |
Nope. This is because |
@qiangxue once created errorHandler object will be returned by ServiceLocator always... |
You may try the following. However you probably need to override $handler = new \app\components\ApiErrorHandler;
\Yii::$app->set('errorHandler', $handler);
$handler->register(); |
@qiangxue have you checked the implementation of ServiceLocator? once you have accessed a component, get() will never return a new one that may have been registered with set() |
@cebe You are right. I have fixed the issue. However, the issue reported here is different. It's because of the special handling at : https://github.com/yiisoft/yii2/blob/master/framework/base/Application.php#L305 |
@qiangxue i have PHP Fatal Error
right after calling $handler->register(); |
@MUTOgen this looks like you are using Yii without importing it in the namespace. add |
@cebe importing doesn't work.... i guess it's because of dealing with register(); |
can you please post the full error stack trace? |
@cebe looks pretty "simple"
|
have you made any changes to app index.php? if yes, show the whole file please. |
No, i didn't // comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/../config/web.php');
(new yii\web\Application($config))->run(); |
When i comment line $handler = new \app\components\ApiErrorHandler;
\Yii::$app->set('errorHandler', $handler);
//$handler->register(); There is no fatals |
where is this line? in which file? |
public function init()
{
parent::init();
$handler = new \app\components\ApiErrorHandler;
\Yii::$app->set('errorHandler', $handler);
//$handler->register();
} It's init in module class |
now this option to overwrite handler works for me in module init method $handler = new \app\components\ApiErrorHandler;
\Yii::$app->set('errorHandler', $handler);
$handler->register(); |
Is it possible to modify some components on fly in modules?
I try something like this:
But object of errorHandler doesn't change (it's \yii\web\ErrorHandler by default)
The text was updated successfully, but these errors were encountered: