Page 1 of 1

PHP Notice: Undefined variable: username

Posted: Thu Sep 08, 2016 11:55 pm
by vagabondelmer
Everytime I go to any admin functions in the backend, I am getting the following error (error log) while in the admin panel of Opencart version 2.3.0.2

2016-09-08 9:29:19 - PHP Notice: Undefined variable: username in /home/sitename/public_html/storename/admin/view/template/common/column_left.tpl on line 5

Anyone know how to fix it? ???

Re: PHP Notice: Undefined variable: username

Posted: Fri Sep 09, 2016 4:01 am
by vagabondelmer
I found an explanation in http://stackoverflow.com/questions/1917 ... n-opencart

Can I assume the following statement is correct;

PHP Notice: Undefined variable: username in
2016-09-08 12:53:35 - PHP Notice: Undefined variable: username in /home/sitename/public_html/storename/admin/view/template/common/column_left.tpl on line 5;

Here is line 5
<img src="<?php echo $image; ?>" alt="<?php echo $firstname; ?> <?php echo $lastname; ?>" title="<?php echo $username; ?>" class="img-circle" />

The reason why it's undefined is because it hasn't been set in the controller file first.

Opencart uses the MVC architecture, varibles are defined in the Controller, then used within the Template / View files. For this reason, it will always evaluate false using isset()

variable $username is not set,

to avoid this error use if(isset($username))

The code missing from the controller file (located: admin/controller/common/column_left.php) would be:

if(isset($username))
$this->data['username'] = $this->config->get('username');

Is this correct? O0

Re: PHP Notice: Undefined variable: username

Posted: Tue Sep 20, 2016 5:22 am
by huntbee
Your understanding in PHP is correct, however in this case, the issue needs to be fixed by updating the code Line no. 5 in admin/view/template/common/column_left.tpl as given below

Code: Select all

<img src="<?php echo $image; ?>" alt="<?php echo $firstname; ?> <?php echo $lastname; ?>" title="<?php echo $firstname; ?> <?php echo $lastname; ?>" class="img-circle" />
The reason is variable $username is not defined in the controller file. Instead you can use the firstname lastname.

Re: PHP Notice: Undefined variable: username

Posted: Thu Oct 13, 2016 2:45 am
by dharam81
huntbee wrote:Your understanding in PHP is correct, however in this case, the issue needs to be fixed by updating the code Line no. 5 in admin/view/template/common/column_left.tpl as given below

Code: Select all

<img src="<?php echo $image; ?>" alt="<?php echo $firstname; ?> <?php echo $lastname; ?>" title="<?php echo $firstname; ?> <?php echo $lastname; ?>" class="img-circle" />
The reason is variable $username is not defined in the controller file. Instead you can use the firstname lastname.
i was getting the same error in my 2.3.0.2 site and replaced the code as suggested by you.

Thanks

Re: PHP Notice: Undefined variable: username

Posted: Thu Nov 17, 2016 3:57 pm
by BumbleBee76
huntbee wrote:Your understanding in PHP is correct, however in this case, the issue needs to be fixed by updating the code Line no. 5 in admin/view/template/common/column_left.tpl as given below

Code: Select all

<img src="<?php echo $image; ?>" alt="<?php echo $firstname; ?> <?php echo $lastname; ?>" title="<?php echo $firstname; ?> <?php echo $lastname; ?>" class="img-circle" />
The reason is variable $username is not defined in the controller file. Instead you can use the firstname lastname.
I had exactly the same problem, this fixed it, thanks :)

Re: PHP Notice: Undefined variable: username

Posted: Fri Feb 24, 2017 2:41 am
by Marine Life
I was having the same issue, i found this topic and replace the old code with the new one now it's working properly.

Thank you so mcuh. :D