Working with PHP Undefined Notification

I am trying to fix this but I cannot. I found some tutorials but I couldn't fix it.

My friend and I are working on the same version and it works on his PC without any problem, but for me it is not. We use the same files, I copied it from him.

What's the matter and why won't this job work on my PC?

Here is my 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>

      

when i go to server i get this error:

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

and this applies to:

'tabs'       => $tabs,

      

to fix it, I added the following also above my file:

$tabs = array();

      

Now when I do this it works and it doesn't give any error, but it just navigates to the page and doesn't show any content. Please help, I am spending too much time on this.

if i put this in my code:

print_r ($ systemInfoData);

I get:

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 ) )

      

+3


source to share


2 answers


The problem is caused by the variable $tabs

not being defined.

You have two options, as rightly mentioned by other contributors:

I. (Preferred)

Define the variable before using it.

II. (Not recommended)

The error is not showing on your friend's PC due to the level error_reporting

set in his / her environment. Edit the level error_reporting

defined in php.ini

.



To hide php notifications add or edit the following line in php.ini

error_reporting = E_ALL & ~E_NOTICE;

      

Alternatively, you can set the error reporting level directly from your script like this:

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

      

More about error reporting in php here: http://php.net/manual/en/function.error-reporting.php

+2


source


You are getting an error Undefined variable

because your variable $tabs

is undefined.

You have multiple operators if

that could define it, but if they all evaluate to false

, it will remain undefined.



The setting $tabs = array();

defines your variable, but it still has no content.

+1


source







All Articles