Skip to content

Commit

Permalink
Merge pull request #567 from TonisOrmisson/fixed-console-pretty-urls-v1
Browse files Browse the repository at this point in the history
v1: fixed pretty-urls not working from console apps
  • Loading branch information
maxxer authored Oct 10, 2024
2 parents 300b4d9 + 1170563 commit b837304
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fix #546: The profile/show page must not be visible by default, implement configurable policy (TonisOrmisson)
- Fix #397: No more fatal Exceptions when connecting to already taken Social Network (edegaudenzi)
- Ehh: Added option to pre-fill recovery email via url parameter (TonisOrmisson)
- Ehh: Fixed pretty-url rules not initialized for console apps (TonisOrmisson)

## 1.6.3 Mar 18th, 2024

Expand Down
14 changes: 10 additions & 4 deletions src/User/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 @@ -49,10 +50,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 @@ -256,11 +257,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)
{
/** @var $module Module */
$module = $app->getModule('user');
Expand All @@ -274,8 +275,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

0 comments on commit b837304

Please sign in to comment.