Skip to content
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

v2: fixed pretty-urls not working from console apps #566

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/User/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use yii\helpers\ArrayHelper;
use yii\i18n\PhpMessageSource;
use yii\web\Application as WebApplication;
use yii\web\UrlManager;

/**
* Bootstrap class of the yii2-usuario extension. Configures container services, initializes translations,
Expand All @@ -53,10 +54,10 @@ public function bootstrap($app)
$this->initTranslations($app);
$this->initContainer($app, $map);
$this->initMailServiceConfiguration($app, $app->getModule('user'));
$this->initUrlRoutes($app);

if ($app instanceof WebApplication) {
$this->initControllerNamespace($app);
$this->initUrlRoutes($app);
$this->initUrlRestRoutes($app);
$this->initAuthCollection($app);
$this->initAuthManager($app);
Expand Down Expand Up @@ -264,11 +265,11 @@ protected function initAuthManager(Application $app)
/**
* Initializes web url routes (rules in Yii2).
*
* @param WebApplication $app
* @param Application $app
*
* @throws InvalidConfigException
*/
protected function initUrlRoutes(WebApplication $app)
protected function initUrlRoutes(Application $app)
{
$module = $this->getModule();
$config = [
Expand All @@ -281,8 +282,13 @@ protected function initUrlRoutes(WebApplication $app)
$config['routePrefix'] = 'user';
}

$urlManager = $app->getUrlManager();
if(!($urlManager instanceof UrlManager)) {
return;
}

$rule = Yii::createObject($config);
$app->getUrlManager()->addRules([$rule], false);
$urlManager->addRules([$rule], false);
}

/**
Expand Down