Post by vagabondelmer » Thu Sep 08, 2016 11:55 pm

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? ???
Last edited by vagabondelmer on Fri Sep 09, 2016 4:02 am, edited 1 time in total.

User avatar
Newbie

Posts

Joined
Fri Jun 17, 2016 7:18 am

Post by vagabondelmer » Fri Sep 09, 2016 4:01 am

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

User avatar
Newbie

Posts

Joined
Fri Jun 17, 2016 7:18 am

Post by huntbee » Tue Sep 20, 2016 5:22 am

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.

HuntBee OpenCart Services
https://www.huntbee.com


User avatar
New member

Posts

Joined
Sun Nov 01, 2015 4:01 am
Location - India

Post by dharam81 » Thu Oct 13, 2016 2:45 am

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

Active Member

Posts

Joined
Mon Apr 30, 2012 8:26 pm

Post by BumbleBee76 » Thu Nov 17, 2016 3:57 pm

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

User avatar
Newbie

Posts

Joined
Thu Nov 10, 2016 8:27 pm
Location - South Africa

Post by Marine Life » Fri Feb 24, 2017 2:41 am

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

Newbie

Posts

Joined
Fri Feb 03, 2017 6:22 am
Location - Bahrain
Who is online

Users browsing this forum: No registered users and 51 guests