Note that there are some explanatory texts on larger screens.

plurals
  1. POphp: failing when including a file that is defined in an array
    primarykey
    data
    text
    <p>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 :</p> <pre><code>function getPage(){ $page=array( 'title'=&gt;$this-&gt;title, 'content'=&gt;$this-&gt;content, 'module'=&gt;$this-&gt;module ); return $page; } </code></pre> <p>And in pageview.php I call it like this : <code>$elements=$page-&gt;getPage();</code> 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) : </p> <pre><code> echo &lt;&lt;&lt;EOT &lt;div class='row-fluid'&gt; &lt;H1&gt; title:$elements[title]&lt;/H1&gt;&lt;/br&gt; $elements[content] $elements[module] &lt;/div&gt; EOT; </code></pre> <p>Now here comes the problem. I have a function called includeModule, which is like this : </p> <pre><code>function includeModule($page){ $page=strtolower($page); if(file_exists("modules/".$page."php")) include("/modules/".$page."php"); else Echo "No such Module Exists :".$page." &lt;/br&gt;"; } </code></pre> <p>Now lets say I want to include a page named "tax.php". If I use <code>include("/modules/tax.php)";</code> it works just fine. If I try though to use <code>include("/modules/".$elements[module].".php)";</code> 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.</p> <p>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) ?</p> <p>Any help on this ? </p> <p>edit: i already tried removing the / but if i do it includes nothing again</p> <p>edit: i've change the function a litle so i can get some feedback </p> <pre><code>if(file_exists("modules/".$page.".php")){ echo "&lt;p&gt;file exists&lt;/p&gt;"; include("modules/".$page."**.**php"); }else{ echo getcwd(); Echo "&lt;p&gt;No such Module Exists :".$page."&lt;/p&gt;"; } </code></pre> <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 :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload