使用PHP通知未定义变量

我正在尝试修复此问题一段时间,但不能.我找到了一些教程,但无法修复.

我和我的朋友使用的是同一版本,并且可以在他的PC上正常使用-但对我而言不会.我们使用的是相同的文件,我从他那里复制了我的文件.

这是怎么回事,为什么在我的PC上无法正常工作?

这是我的index.php

<?php
/* @var $this SystemManagementController */
/* @var $dataProvider CActiveDataProvider */
?>
<?php
$this->breadcrumbs = array(
    Yii::t('mainmenu', 'System Management'),
);

$contentTabUsers = $this->renderPartial('_tab_users', array(
    'model'              => $userModel,
    'columns'            => $userColumns,
    ), $return               = true);
$contentTabStates    = $this->renderPartial('_tab_states', array('model'                     => $stateModel), $return                    = true);
$contentTabPriorities    = $this->renderPartial('_tab_priorities', null, $return                     = true);
$contentTabProperties    = $this->renderPartial('_tab_properties', null, $return                     = true);

$upgradeLog = 'tbd'; //new UpgradeLog();

$systemInfo = new SystemInfo();
try
{
    $systemInfoData = array(
        'System Info'    => $systemInfo->getServerInfo(),
        'Apache'         => $systemInfo->getApacheInfo(),
        'MySQL Info'     => $systemInfo->getMysqlInfo(),
    );
}
catch (Exception $ex)
{
    Yii::log('Could not retrieve system info, exception thrown with message: ' . $ex->getMessage(), CLogger::LEVEL_ERROR);
    $systemInfoData = array();
}
$contentTabSysinfo = $this->renderPartial('_tab_sysinfo', array(
//  'model'                  => $upgradeLog,
//  'upgradeLogDataProvider' => $this->getUpgradeLogDataProvider(),
//  'upgradeScripts'         => $this->getAllInfoUpgradeScripts(),
    'systemInfo' => $systemInfoData,
    'phpinfo'    => $this->getBasicPhpInfo(),
    ), $return       = true
);




// get the filter value to show max lines
$showMaxLines    = (int) $this->getAppRequest()->getParam('log_show_max_lines', 50);
$contentTabLog   = $this->renderPartial('_tab_log', array(
    'applicationLog' => $this->getLog($showMaxLines),
    'showMaxLines'   => $showMaxLines,
    // 'log_show_max_lines' is a placeholder for the js value in the template
    'filterUrl'      => $this->getYiiApp()->createUrl('systemManagement/index', array('log_show_max_lines' => null)),
    ), $return               = true
);
Yii::app()->user->setState('activeSystemmanagementTab', 'system_info');

$tabs = array();
if (Yii::app()->user->checkAccess('Systemmanagement.users'))
{
    $tabs[Yii::t('systemmanagement', 'Users')] = array('content'     => $contentTabUsers, 'id'       => 'users');
}
if (Yii::app()->user->checkAccess('Systemmanagement.states'))
{
    $tabs[Yii::t('systemmanagement', 'States')] = array('content'    => $contentTabStates, 'id'      => 'states');
}
if (Yii::app()->user->checkAccess('Systemmanagement.priorities'))
{
    $tabs[Yii::t('systemmanagement', 'Priorities')] = array('content'    => $contentTabPriorities, 'id'      => 'priorities');
}
if (Yii::app()->user->checkAccess('Systemmanagement.properties'))
{
    $tabs[Yii::t('systemmanagement', 'Properties')] = array('content'    => $contentTabProperties, 'id'      => 'properties');
}
if (Yii::app()->user->checkAccess('Systemmanagement.sysinfo'))
{
    $tabs[Yii::t('systemmanagement', 'System Info')] = array('content'   => $contentTabSysinfo, 'id'         => 'system_info');
}
if (Yii::app()->user->checkAccess('Systemmanagement.log'))
{
    $tabs[Yii::t('systemmanagement', 'Log')] = array('content'   => $contentTabLog, 'id'         => 'log');
}

$this->widget('zii.widgets.jui.CJuiTabs', array(
    'tabs'       => $tabs,
    // additional javascript options for the tabs plugin
    'options'    => array(
        'collapsible'    => true,
        'hide'           => 'fade',
        'activeTab'      => Yii::app()->user->getState('activeSystemmanagementTab'),
//      'show'           => 'highlight',
        //TODO @see http://www.bsourcecode.com/2012/11/how-to-handle-cjuitabs-in-yii/
        'selected'       => isset(Yii::app()->session['tabid']) ? Yii::app()->session['tabid'] : 0,
        'select'         => 'js:function(event, ui) {
            var index=ui.index;
            $.ajax({
                "url":"' . Yii::app()->createUrl('site/tabidsession') . '",
                "data":"tab="+index,
            });
    }',
    )
    )
);
?>
<script type="text/javascript">
    function changeIsactive(id)
    {
        $.ajax({
            type: 'post',
            url: "<?php echo Yii::app()->createUrl('usp/AjaxSetuspOnOff') ?>",
            datatype: 'json',
            data: "MeId=" + id,
            success: function (data) {
                // if page access denied show the error msg
                var hasError = $("<div></div>").append(data).find("#content div.error").length > 0;
                if (hasError)
                {
                    $("#flashmsg").show().addClass('flash-error').html('<?php echo Yii::t('systemwide', 'You Are Not Authorized to Turn On/Off this ELement'); ?>').animate({opacity: 0.9}, 3500).fadeOut("slow");
                    return false;
                } else {
                    if (data != 'error')
                    {
                        if (data)
                        {
                            $('#onOff_' + id).addClass(data);
                        }
                        else {
                            $('#onOff_' + id).removeClass('checked');
                        }
                    }
                    else
                    {
                        $("#flashmsg").show().addClass('flash-error').html('<?php echo Yii::t('systemwide', 'You Are Not Authorized to Turn On/Off this ELement'); ?>').animate({opacity: 0.9}, 3500).fadeOut("slow");
                    }
                    return false;
                }
            },
            error: function (jqXHR, exception) {
                $("#flashmsg").show().addClass('flash-error').html('<?php echo Yii::t('systemwide', 'You Are Not Authorized to Turn On/Off this ELement'); ?>').animate({opacity: 0.9}, 3500).fadeOut("slow");
            }
        });
    }
</script>

当我转到服务器时,出现此错误:

PHP notice Undefined variable: tabs /var/www/private/protected/views/systemmanagement/index.php(84)

这是指:

'tabs'       => $tabs,

为了解决这个问题,我在文件上添加了以下内容:

$tabs = array();

现在,当我执行此操作时,它可以工作并且不会出现任何错误,但是它只会转到页面,并且不会显示任何内容.请帮助我为此花费太多时间.

如果我把它放在我的代码中:

print_r($systemInfoData);

我得到:

Array ( [System Info] => Array ( [OS] => Linux #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 [Machine Type] => x86_64 [Server Name] => 192.168.33.10 [Server IP Address] => 192.168.33.10 ) [Apache] => Array ( [version] => Apache/2.4.12 (Ubuntu) [Loaded Modules] => core, mod_so, mod_watchdog, http_core, mod_log_config, mod_logio, mod_version, mod_unixd, mod_access_compat, mod_alias, mod_auth_basic, mod_authn_core, mod_authn_file, mod_authz_core, mod_authz_groupfile, mod_authz_host, mod_authz_user, mod_autoindex, mod_cgi, mod_deflate, mod_dir, mod_env, mod_expires, mod_filter, mod_headers, mod_include, mod_mime, prefork, mod_negotiation, mod_php5, mod_reqtimeout, mod_rewrite, mod_setenvif, mod_status ) [MySQL Info] => Array ( [Server version] => 5.5.43-0ubuntu0.12.04.1 [Meta information] => Uptime: 11334 Threads: 1 Questions: 11476 Slow queries: 0 Opens: 76 Flush tables: 1 Open tables: 54 Queries per second avg: 1.012 ) )

解决方法:

该问题是由于未定义变量$tabs引起的.

正如其他贡献者所正确提到的,您有两个选择:

I.(最好)

在使用变量之前定义它.

二. (不建议)

由于好友环境中设置的error_reporting级别,因此该错误未显示在您朋友的PC上.编辑php.ini中定义的error_reporting级别.

为了隐藏php通知,请在php.ini中添加或编辑以下行

error_reporting = E_ALL & ~E_NOTICE;

或者,您可以直接从脚本中设置错误报告级别,如下所示:

// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);

在此处阅读有关错误报告的更多信息:http://php.net/manual/en/function.error-reporting.php

上一篇:docker swarm 集群搭建


下一篇:php-Android应用无法访问Vagrant Homestead托管的Web API