I created Joomla template and tried to include a PHP script.

My index.php code:

defined('_JEXEC') or die; 
use Joomla\CMS\Uri\Uri;

<!doctype html>
<meta charset="utf-8">
<title>Untitled Page</title>
<meta name="generator" content="WYSIWYG Web Builder 16 - http://www.wysiwygwebbuilder.com">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="index.css" rel="stylesheet">
//$myHeader = $_SERVER['DOCUMENT_ROOT']."/templates/".$this->template."/script/header.php";

$myHeader = JPATH_SITE."/templates/".$this->template."/script/header.php";
echo "<br>".$myHeader;
include $myHeader
   <div id="FlexContainer1">
   <div id="Layer1" style="position:fixed;text-align:center;left:0;top:0;right:0;height:142px;z-index:4;left:0px; width:100%">
      <div id="Layer1_Container" style="width:100%">
   <div id="FlexContainer2">
      <div id="wb_FlexContainer3">
         <div id="FlexContainer3" style="min-height:50px; ">
      <div id="FlexContainer4">
      <div id="wb_FlexContainer5">
         <div id="FlexContainer5" style="min-height:50px;">

The $_SERVER['DOCUMENT_ROOT'] has a problem with the wrapper, so I commented it out. I surfed on the internet and found an article suggesting JPATH_SITE, but then I got a 0 - Class "Uri" not found message. I surfed again and found information that I should use use Joomla\CMS\Uri\Uri, but the problem still remains.

this is my header.php codes

//defined('_JEXEC') or die; //sudah ada di wysiwyg head
//use Joomla\CMS\Uri\Uri; //sudah ada di wysiwyg head

$myjquery = Uri::root()."templates/".$this->template."/jquery-1.12.4.min.js";
$myIndexCss = Uri::root()."templates/".$this->template."/index.css";

<jdoc:include type="head"/>

<link rel="stylesheet" href="media/system/css/joomla-fontawesome.min.css">
<link rel="stylesheet" href="<?php echo $myIndexCss ?>">

<script src="<?php echo $myjquery; ?>"></script>

I use these codes before and work fine but not through inclusion, I mean these codes were written directly into index.php

  • There is no use of Uri class in your posted snippet. Enable debug and inspect the stack trace to know where exactly it's used. Could be inside header.php.
    – Sharky
    Commented Dec 14, 2022 at 15:55
  • Can you paste up the code in your View class? If you put the use Joomla\CMS\Uri\Uri; before the class statement in your View you might resolve the issue. As @Sharky has said there is nothing in what you have pasted that appears to use URI, I suspect it is something in your View class.
    – Irata
    Commented Dec 15, 2022 at 22:42
  • I don't have any other files except these two files, index.php, and header.php, I wrote a use Joomla\CMS\Uri\Uri; as early as possible, as the first line must be defined('_JEXEC') or die; Commented Dec 16, 2022 at 5:47

1 Answer 1


Symbol imports using use statement are file-scoped (except when using inside namespace blocks). Which means you have to import them in the file where it's used. So you have to move use Joomla\CMS\Uri\Uri; statement from index.php to header.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.