我正在尝试将事件附加到名为HumHub的Yii应用程序的全局范围,但是,当我尝试通过全局的“TopMenu”运行函数时,它似乎没有做任何事情。可能是因为我没有使用$event
变量范围?
我正在尝试创建一个开发模式模块,以防止管理员在激活时查看系统,但不能访问任何人。我知道在所有页面上获取代码的唯一全局方式(我对HumHub和Yii的理解有限)是TopMenu,因为它出现在所有页面上(除了登录页面,当访客模式处于活动状态时被禁用)
autostart.php
Yii::app()->moduleManager->register(array(
'id' => 'devmode',
'class' => 'application.modules.devmode.DevModeModule',
'import' => array(
'application.modules.devmode.*',
),
// Events to Catch
'events' => array(
array('class' => 'AdminMenuWidget', 'event' => 'onInit', 'callback' => array('DevModeEvents', 'onAdminMenuInit')),
array('class' => 'TopMenuWidget', 'event' => 'onInit', 'callback' => array('DevModeEvents', 'devBlock')),
array('class' => 'DashboardSidebarWidget', 'event' => 'onInit', 'callback' => array('DevModeModule', 'onSidebarInit')),
),
));
DevModeEvents.php
<?php
/**
* Defines the module events
*
* @package humhub.modules.devmode.events
* @author Jordan Thompson
*/
class DevModeEvents {
public static function onAdminMenuInit($event)
{
$event->sender->addItem(array(
'label' => Yii::t('devmode.base', 'Development Mode'),
'url' => Yii::app()->createUrl('//devmode/config/config'),
'group' => 'settings',
'icon' => '<i class="fa fa-lock"></i>',
'isActive' => (Yii::app()->controller->module && Yii::app()->controller->module->id == 'devmode' && Yii::app()->controller->id == 'admin'),
'sortOrder' => 300,
));
}
public static function devBlock($event) {
$devMode = HSetting::Get('devMode', 'devmode');
if ($devMode == 1 ) {
if (!Yii::app()->user->isGuest) {
if (!Yii::app()->user->isAdmin()) {
throw new CHttpException('418', Yii::t('devmode.base', Yii::app()->name . ' is currently under maintenance, check back later.'));
}
} else {
throw new CHttpException('418', Yii::t('devmode.base', Yii::app()->name . ' is currently under maintenance, check back later.'));
}
}
}
}
答案 0 :(得分:3)
将排序顺序更改为1,并使用css
访问它li:nth-child(1) {
//do something;
}