![]() |
Template Customization Using PHP Objects
I have a problem that I don't think is quite covered in all the threads I've looked at, although this thread looks like it has something close to what I'm looking for.
My web page header and footer are defined in a PHP class called Navigation. I pass a number of variables to the methods within the class, then have the following code that places header and footer, respectively, on the page: Code:
echo $Navigation->getHeader(); <added> For clarification, my header includes everything from the <html> tag through the <body> tag. </added> |
Hi. To use echo $Navigation->getHeader(); and echo $Navigation->getFooter(); perhaps try the following.
At the top of search_function.php add: PHP Code:
PHP Code:
PHP Code:
Remember to remove any "word" wrapping in the above code. |
Something is missing, I think. Just to make sure I didn't have anything I overlooked in setting up the object oriented code, I added the following (in bold) to a section of code you told me to add:
Code:
ob_start(); |
Hi. Change the following:
PHP Code:
PHP Code:
|
Yes, the header displays just fine when I do that.
|
Hi. In search_function.php the "ob" code is at the top, before the $t_mstrings = compact('my_header_file','my_footer_file',... part? Note that in $t_strings there are no dollar signs on the right hand side. Are you using a template that came with PhpDig, and <phpdig:my_header_file/> and <phpdig:my_footer_file/> are used in the template file? It seems like there may just be a typo somewhere as $my_header_file and $my_footer_file are holding content.
|
In search_function.php, the "ob" part is the very first statements in the code, and looks like this.
Code:
ob_start(); Code:
if ($template == 'array' || is_file($template)) { The config.php file has this: Code:
$template = "$relative_script_path/templates/template.php"; I took a phpDig template and modified it so that the header and footer have this, respectively: Code:
<phpdig:my_header_file/> |
Hi. Try either modifying the .../PHP_DIG/templates/template.php file so that it contains the <phpdig:my_header_file/> and <phpdig:my_footer_file/> tags or setting the $template variable in the config.php file to the PhpDig template that uses the <phpdig:my_header_file/> and <phpdig:my_footer_file/> tags. It looks like one template has the tags but another template sans tags is being used by PhpDig.
|
I've messed with this for quite a while this evening, and I just don't see where the problem is. One thing I noticed is that the "else" condition of the following code is being executed, rather than the "if" condition. Is this what should happen?
Code:
if ($template == 'array' || is_file($template)) { |
>> Is this what should happen?
Hi. That's okay. One thing I did notice is that if you call http://www.napathon.net/ssi/header.php and http://www.napathon.net/ssi/footer.php from the browser, the "call to a member function on a non-object" error appears. |
Well, now I'm really confused. I have all the code in search.php that sets the value of the header and footer variables, instantiates the class, etc. The only thing that is in header.php is this.
Code:
<?php |
>> Have I completely misunderstood what I need to do in order to set this up?
Hi. Nah, I think that the header.php and footer.php files need to have access to the header-footer class/script so that echo $Navigation->getHeader(); and echo $Navigation->getFooter(); output the header and footer. Perhaps add an include("/path/to/class/script.php"); into header.php and footer.php, and then call just header.php and footer.php from the browser to check and see if the HTML is onscreen. |
Still no joy. This may be overkill but I've saved all the relevant files with .txt file extensions and uploaded them to the Web server into the same directory as their .php counterpart. Maybe this will help diagnose the problem.
http://www.napathon.net/PHP_DIG/search.txt http://www.napathon.net/ssi/header.txt http://www.napathon.net/ssi/footer.txt http://www.napathon.net/PHP_DIG/includes/config.txt http://www.napathon.net/PHP_DIG/libs...h_function.txt http://www.napathon.net/PHP_DIG/templates/template.txt |
Hi. Change header.php back to the following:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
It worked! :D Thanks so much for sticking with me until we got this problem solved. I just have some minor formatting issues to deal with now, but that's ok. They're only CSS things, and I can handle that. It's just so much nicer maintaining my template in one place.
Thanks again. |
All times are GMT -8. The time now is 04:36 PM. |
Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.