NLT Posted May 20, 2012 Share Posted May 20, 2012 I've created a template system. I've got a function to assign a page (the templates are in /template/skin). It all works fine in the main root, but if I had a directory it won't work. $dir = "template/skin"; That is found in template/ I need to be able to assign the template even in directories. Quote Link to comment Share on other sites More sharing options...
NLT Posted May 20, 2012 Author Share Posted May 20, 2012 And I've also tried using $_SERVER['SERVER_NAME']; but because it's a class it won't work. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 20, 2012 Share Posted May 20, 2012 Try defining the path from the root of the site by including a forward slash at the beginning. Otherwise, without it, you are defining it relative from the current working directory. $dir = "/template/skin"; Quote Link to comment Share on other sites More sharing options...
NLT Posted May 20, 2012 Author Share Posted May 20, 2012 Try defining the path from the root of the site by including a forward slash at the beginning. Otherwise, without it, you are defining it relative from the current working directory. $dir = "/template/skin"; Warning: file_get_contents(/template/skin/404.tpl) [function.file-get-contents]: failed to open stream: No such file or directory Although if I type /template/skin/404.tpl with the document I'm on (no index.php etc) then it downloads a tpl file. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 20, 2012 Share Posted May 20, 2012 You never stated you were using file_get_contents()! That would use the file system directory structure and not the web directory structure. I don't know why you would be using file_get_contents() instead of an include() anyway. Quote Link to comment Share on other sites More sharing options...
NLT Posted May 20, 2012 Author Share Posted May 20, 2012 Didn't think there was much difference between include and file_get_contents. I changed it to [m]include[/b] and it's still saying directory not found. Quote Link to comment Share on other sites More sharing options...
NLT Posted May 20, 2012 Author Share Posted May 20, 2012 Just remembered why I'm using file_get_contents! It's because I'm replacing variables (or setting variables) to parse through the HTML. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 21, 2012 Share Posted May 21, 2012 As stated, file_get_contents() is based upon the file system directory, not the web directory. I would suggest using a config file that is loaded on every page that includes a variable to the location of the templates folder. Quote Link to comment Share on other sites More sharing options...
NLT Posted May 21, 2012 Author Share Posted May 21, 2012 Would something like this work in configuration.php (as it's called every file, and in root): $template->SetDir("/template/skin"); and then in the template: public $dir; function SetDir($dir) { $this->dir = $dir; } Then replace everything with that? Quote Link to comment Share on other sites More sharing options...
NLT Posted May 21, 2012 Author Share Posted May 21, 2012 I have tried using what I have above and getting the same thing. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 22, 2012 Share Posted May 22, 2012 You will have to define the path from the root of the file system. You cannot define a relative path since you are calling it from different places in the file system. Quote Link to comment Share on other sites More sharing options...
NLT Posted May 22, 2012 Author Share Posted May 22, 2012 That's what I did. It still gives me an error in a directory Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 23, 2012 Share Posted May 23, 2012 That's what I did. It still gives me an error in a directory Can you show how you did it? Because THIS is a relative reference $template->SetDir("/template/skin"); Quote Link to comment Share on other sites More sharing options...
NLT Posted May 23, 2012 Author Share Posted May 23, 2012 I've done exactly what I've showed above, I'm not sure what, if, you need anything else. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 23, 2012 Share Posted May 23, 2012 As I said, that path is a relative path. That means it is relative from the current working directory. The workign directory is different based upon which file is being run. You need the path to be hard coded from the root of the file path, e.g. c:\some_directory\another_directory\. But, if you are on a shared host, I have no idea what it would look like. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 23, 2012 Share Posted May 23, 2012 But, if you are on a shared host, I have no idea what it would look like. One quick way to find out is when you have error reporting on and try to include a file that doesn't exist, it will tell you where it tried to look. There's your path. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.