Enh: Allow any url route as homepage

This commit is contained in:
Lucas Bartholemy 2017-03-18 01:54:43 +01:00
parent 7f43a506a3
commit 16bfea0d50
4 changed files with 66 additions and 2 deletions

View File

@ -9,6 +9,8 @@
namespace humhub\components;
use Yii;
use yii\helpers\Url;
use yii\base\Exception;
/**
* @inheritdoc
@ -21,6 +23,11 @@ class Application extends \yii\web\Application
*/
public $controllerNamespace = 'humhub\\controllers';
/**
* @var string|array the homepage url
*/
private $_homeUrl = null;
/**
* @inheritdoc
*/
@ -35,10 +42,32 @@ class Application extends \yii\web\Application
if (Yii::getAlias('@webroot-static', false) === false) {
Yii::setAlias('@webroot-static', '@webroot/static');
}
parent::bootstrap();
}
/**
* @return string the homepage URL
*/
public function getHomeUrl()
{
if ($this->_homeUrl === null) {
throw new Exception('Home URL not defined!');
} elseif (is_array($this->_homeUrl)) {
return Url::to($this->_homeUrl);
} else {
return $this->_homeUrl;
}
}
/**
* @param string|array $value the homepage URL
*/
public function setHomeUrl($value)
{
$this->_homeUrl = $value;
}
/**
* @inheritdoc
*/

View File

@ -3,7 +3,8 @@
$config = [
'id' => 'humhub',
'bootstrap' => ['humhub\components\bootstrap\LanguageSelector'],
'defaultRoute' => '/dashboard/dashboard',
'homeUrl' => ['/dashboard/dashboard'],
'defaultRoute' => '/home',
'layoutPath' => '@humhub/views/layouts',
'components' => [
'request' => [

View File

@ -0,0 +1,33 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\controllers;
use humhub\components\Controller;
use yii\helpers\Url;
/**
* HomeController redirects to the home page
*
* @author luke
* @since 1.2
*/
class HomeController extends Controller
{
/**
* Redirects to the home controller/action
*
* @return \yii\web\Response
*/
public function actionIndex()
{
return $this->redirect(Url::home());
}
}

View File

@ -91,6 +91,7 @@ HumHub Change Log
- Fix: Better notification compatiblity - mail views and enabled WebNotificationTarget
- Fix #2312: Pinned post appears twice on stream
- Enh: Added option to show/hide deactivated user content in stream
- Enh: Allow any url route as homepage by homeUrl array application parameter
1.2.0-beta.2 (February 24, 2017)