loadTemplatefile() has me confused...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
OrcaSoul
Forum Newbie
Posts: 8
Joined: Wed Aug 26, 2009 10:08 pm

loadTemplatefile() has me confused...

Post by OrcaSoul »

I am new to php, so really need some advice on a problem I am encountering!

I am using a script found in a book on PHP & MySQL, and am getting errors at one point:

The code is:

Code: Select all

 
function orcatoolsTemplate($pageBody, $pageTitle = P_TITLE)
   {
      $this->template = $this->HTML_Template_ITX(D_TEMPLATES);
      $this->loadTemplatefile(T_SKELETON, true, true);  //this is where the error occurs
      $this->setVariable("TITLE", $pageTitle);
      $this->addBlockFile("PAGE_BODY", "pageBody", "{$pageBody}");
   }
 
Where:
D_TEMPLATES = "/usr/local/apache2/htdocs/OrcaTools/templates/"
T_SKELETON = "orcatools.tpl"

The error I get:

Code: Select all

 
[PHP Error 20090904185159]WARNING on line 914 in C:\xampp\php\PEAR\HTML\Template\IT.php.
[PHP Error 20090904185159]Error: "fopen(/usr/local/apache2/htdocs/OrcaTools/templates/orcatools.tpl) [function.fopen]: failed to open stream: No such file or directory" (error #2).
[PHP Error 20090904185159]Client IP: ::1
 
UNHANDLED ERROR on line 915 in C:\xampp\php\PEAR\HTML\Template\IT.php.
[PHP Error 20090904185159]Error: "Non-static method PEAR::raiseError() should not be called statically, assuming $this from incompatible context" (error #2048).
[PHP Error 20090904185159]Client IP: ::1
 
UNHANDLED ERROR on line 993 in C:\xampp\php\PEAR\HTML\Template\IT.php.
[PHP Error 20090904185159]Error: "Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context" (error #2048).
[PHP Error 20090904185159]Client IP: ::1
 
This seems to indicate that /usr/local/apache2/htdocs/OrcaTools/templates/orcatools.tpl does not exist - and yet it IS in the folder OrcaTools/templates/...

I've tried specifically calling using the file name - both the short & long versions, I still get the same errors.

What am I missing here?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: loadTemplatefile() has me confused...

Post by requinix »

Look carefully at that file path:

Code: Select all

/usr/local/apache2/htdocs/OrcaTools/templates/
Are you sure that exact file path exists on your Windows machine?
OrcaSoul
Forum Newbie
Posts: 8
Joined: Wed Aug 26, 2009 10:08 pm

Re: loadTemplatefile() has me confused...

Post by OrcaSoul »

tasairis wrote:Look carefully at that file path:

Code: Select all

/usr/local/apache2/htdocs/OrcaTools/templates/
Are you sure that exact file path exists on your Windows machine?
When I go to the folder with the file, the path that is shown is:

Code: Select all

C:\xampp\htdocs\OrcaTools\templates
So, not a literal one...and I was wondering about that but since I'm new to PHP wasn't sure how it was read in the XAMPP Apache local server.

Edit to add: I did try the literal path hard coded, didn't work.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: loadTemplatefile() has me confused...

Post by requinix »

OrcaSoul wrote:Edit to add: I did try the literal path hard coded, didn't work.
What's the code that defines this path?
OrcaSoul
Forum Newbie
Posts: 8
Joined: Wed Aug 26, 2009 10:08 pm

Re: loadTemplatefile() has me confused...

Post by OrcaSoul »

tasairis wrote:
OrcaSoul wrote:Edit to add: I did try the literal path hard coded, didn't work.
What's the code that defines this path?
I'm assuming it's part of the XAMPP Apache PHP - being new to this can't say for sure.

I can do some digging and see if there is something setting the path inside the files I have.

BTW, I just retried the hard code - still didn't work but I did notice that with the entire path it showed a combined string in the second line of the error message:

Code: Select all

[PHP Error 20090904232917]Error: "fopen(/usr/local/apache2/htdocs/OrcaTools/templates/C:/xampp/htdocs/OrcaTools/templates/orcatools.tpl)
So, it appears that the function itself in PHP creates it's own path...
OrcaSoul
Forum Newbie
Posts: 8
Joined: Wed Aug 26, 2009 10:08 pm

Re: loadTemplatefile() has me confused...

Post by OrcaSoul »

OK, I just did a search on "D_TEMPLATES", and found where it's defined - and I suspect that's where the problem is...

define("D_INSTALL_PATH", "/usr/local/apache2/htdocs");

// Paths -- for these, add trailing slash
define("D_WEB_PATH", "/OrcaTools/");
define("D_CART", D_WEB_PATH . "cart/");
define("D_CARTIMAGES", D_CART . "images/");
define("D_CUSTOMER", D_WEB_PATH . "customer/");
define("D_AUTH", D_WEB_PATH . "auth/");
define("D_ORDER", D_WEB_PATH . "order/");
define("D_SEARCH", D_WEB_PATH . "search/");
define("D_TEMPLATES", D_INSTALL_PATH . D_WEB_PATH . "templates/");
Something to work on in the morning...

I could put the actual hard path in - but, since this will eventually be on a real server, that path won't be correct...I can check with the XAMPP forum, see what they suggest.

Thanks for the help.
Post Reply