I want to include a file, based on a value I get from my database. Inside class page in page.php I have this function to get the data I want :
function getPage(){
$page=array(
'title'=>$this->title,
'content'=>$this->content,
'module'=>$this->module
);
return $page;
}
And in pageview.php I call it like this : $elements=$page->getPage();
The function works just fine and I get my content , which I can manipulate like this for example(I know heredox is not the way to go but please ignore it, it's not the problem) :
echo <<<EOT
<div class='row-fluid'>
<H1> title:$elements[title]</H1></br>
$elements[content]
$elements[module]
</div>
EOT;
Now here comes the problem. I have a function called includeModule, which is like this :
function includeModule($page){
$page=strtolower($page);
if(file_exists("modules/".$page."php")) include("/modules/".$page."php");
else Echo "No such Module Exists :".$page." </br>";
}
Now lets say I want to include a page named "tax.php". If I use include("/modules/tax.php)"; it works just fine. If I try though to use include("/modules/".$elements[module].".php)"; it does nothing ( an yes $elements[module] does contain only the word "tax" ).
I even tried assigning the value of $elements[module] to another variable but nothing.
The strangest part of all is that if I try to use my function ( includeModule), even if I manually set the $page variable to "tax", it still doe not include anything and says that the file does not exist ( even though it does) ?
Any help on this ?
edit: i already tried removing the / but if i do it includes nothing again
edit: i've change the function a litle so i can get some feedback
if(file_exists("modules/".$page.".php")){
echo "<p>file exists</p>";
include("modules/".$page."**.**php");
}else{
echo getcwd();
Echo "<p>No such Module Exists :".$page."</p>";
}
OK solved. thanks for all the answers. By my mistake the trailing slash as well as the dot right before the php extension were left out . thanks for helping :)
getcwd()function.modules/page.php != /modules/page.php! (well, probably not anyway) Check your absolute path$elements[module]is correct when including in a parsed string (but nowhere else).