PhpDig.net

Go Back   PhpDig.net > PhpDig Forums > How-to Forum

Reply
 
Thread Tools
Old 02-01-2004, 09:44 AM   #1
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
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();

echo $Navigation->getFooter();
How can I incorporate a PHP object into my template so that I don't have to maintain it in two separate places, one for the rest of my site and the other for phpDig?

<added>
For clarification, my header includes everything from the <html> tag through the <body> tag.
</added>

Last edited by vinyl-junkie; 02-01-2004 at 09:51 AM.
vinyl-junkie is offline   Reply With Quote
Old 02-05-2004, 06:49 AM   #2
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
Hi. To use echo $Navigation->getHeader(); and echo $Navigation->getFooter(); perhaps try the following.

At the top of search_function.php add:
PHP Code:
ob_start();
require(
"/path/to/header.php");
$my_header_file ob_get_contents();
ob_end_clean();

ob_start();
require(
"/path/to/footer.php");
$my_footer_file ob_get_contents();
ob_end_clean(); 
and then in search_function.php replace:
PHP Code:
$t_mstrings =  compact('powered_by_link','title_message','phpdig_version','result_message','nav_bar','ignore_message','ignore_commess','pages_bar','previous_link','next_link','templates_links'); 
with the following:
PHP Code:
$t_mstrings =  compact('my_header_file','my_footer_file','powered_by_link','title_message','phpdig_version','result_message','nav_bar','ignore_message','ignore_commess','pages_bar','previous_link','next_link','templates_links'); 
Make the header.php and footer.php files contain echo $Navigation->getHeader(); and echo $Navigation->getFooter(); respectively, and then use <phpdig:my_header_file/> and <phpdig:my_footer_file/> in the template.

Remember to remove any "word" wrapping in the above code.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-05-2004, 07:58 PM   #3
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
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(); 
require("/home/napathon/public_html/ssi/header.php"); 
$my_header_file = ob_get_contents();
die($my_header_file); 
ob_end_clean();
My header displayed as it should when I did the above. I also made sure that I had followed all your instructions in modifying the code, but when I added the code into the template, it didn't display my header and footer. Any ideas why?
vinyl-junkie is offline   Reply With Quote
Old 02-06-2004, 09:17 AM   #4
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
Hi. Change the following:
PHP Code:
ob_start();
require(
"/path/to/header.php");
$my_header_file ob_get_contents();
ob_end_clean(); 
to the following:
PHP Code:
ob_start();
require(
"/path/to/header.php");
$my_header_file ob_get_contents();
ob_end_clean();
echo 
$my_header_file;
exit(); 
and then call search.php to see if $my_header_file actually contains the header information.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-06-2004, 06:53 PM   #5
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
Yes, the header displays just fine when I do that.
vinyl-junkie is offline   Reply With Quote
Old 02-06-2004, 07:09 PM   #6
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
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.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-06-2004, 07:53 PM   #7
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
In search_function.php, the "ob" part is the very first statements in the code, and looks like this.
Code:
ob_start(); 
require("/home/napathon/public_html/ssi/header.php"); 
$my_header_file = ob_get_contents(); 
ob_end_clean();

ob_start(); 
require("/home/napathon/public_html/ssi/footer.php"); 
$my_footer_file = ob_get_contents(); 
ob_end_clean();
The $t_mstrings statement is toward the bottom of the file, and looks like this:
Code:
if ($template == 'array' || is_file($template)) {
    $phpdig_version = PHPDIG_VERSION;
    $t_mstrings =   compact('my_header_file','my_footer_file','powered_by_link','title_message','phpdig_version','result_message','nav_bar','ignore_message','ignore_commess','pages_bar','previous_link','next_link','templates_links');
Word wrapping was removed.

The config.php file has this:
Code:
$template = "$relative_script_path/templates/template.php";
and that is the correct path and filename for it.

I took a phpDig template and modified it so that the header and footer have this, respectively:
Code:
<phpdig:my_header_file/>

<phpdig:my_footer_file/>
Is there anything I missed?
vinyl-junkie is offline   Reply With Quote
Old 02-06-2004, 08:11 PM   #8
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
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.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-06-2004, 09:54 PM   #9
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
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)) {
    $phpdig_version = PHPDIG_VERSION;
    $t_mstrings =   compact('my_header_file','my_footer_file','powered_by_link','title_message','phpdig_version','result_message','nav_bar','ignore_message','ignore_commess','pages_bar','previous_link','next_link','templates_links');
    $t_fstrings = phpdigMakeForm($query_string,$option,$limite,SEARCH_PAGE,$site,$path,'template',$template);
    if ($template == 'array') {
        return array_merge($t_mstrings,$t_fstrings,array('results'=>$table_results));
    }
    else {
        $t_strings = array_merge($t_mstrings,$t_fstrings);
        phpdigParseTemplate($template,$t_strings,$table_results);
    }
}
vinyl-junkie is offline   Reply With Quote
Old 02-06-2004, 11:22 PM   #10
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
>> 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.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-07-2004, 12:16 AM   #11
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
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
echo $Navigation->getHeader();
?>
Have I completely misunderstood what I need to do in order to set this up?
vinyl-junkie is offline   Reply With Quote
Old 02-07-2004, 12:26 AM   #12
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
>> 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.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-07-2004, 06:11 AM   #13
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
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
vinyl-junkie is offline   Reply With Quote
Old 02-07-2004, 09:36 AM   #14
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
Hi. Change header.php back to the following:
PHP Code:
<?php
echo $Navigation->getHeader();
?>
Change footer.php back to the following:
PHP Code:
<?php
echo $Navigation->getFooter();
?>
Remove the following from search.php and stick it into a new file, say makeheadfoot.php located at /home/napathon/public_html/ssi/makeheadfoot.php:
PHP Code:
/*
--------------------------------------------------------------------------------
My code goes here to incorporate my template
--------------------------------------------------------------------------------
*/
require_once '/home/napathon/public_html/class/Navigation.php';

// This goes into the meta name="description" content field
$MetaDescription "Build your own website search engine using phpDig.";

// This goes into the meta name="keywords" content field
$MetaKeywords "website search engine";

// This goes into the page title
$PageTitle "Search My Website";

// This goes into the table title
$TableTitle $PageTitle;

// Robots meta tag. Leave this as null if you don't intend to use it
$Robots "Index, Follow";

// Instantiate the Navigation class; then build the page header and footer
$Navigation = new Navigation();
$Navigation->addHeader($HTMLTitle$MetaDescription$MetaKeywords$PageTitle$Robots);
$Navigation->addFooter(); 
In search_function.php move the following code to right above $timer = new phpdigTimer('html'); but inside the function:
PHP Code:
ob_start(); 
require(
"/home/napathon/public_html/ssi/header.php"); 
$my_header_file ob_get_contents(); 
ob_end_clean(); 

ob_start(); 
require(
"/home/napathon/public_html/ssi/footer.php"); 
$my_footer_file ob_get_contents(); 
ob_end_clean(); 
Also in search_function.php right before the first ob_start(); call but still inside the function add the following:
PHP Code:
require("/home/napathon/public_html/ssi/makeheadfoot.php"); 
"Inside the function" means the following:
PHP Code:
function phpdigSearch($id_connect$query_string$option='start'$refine=0,
                       
$refine_url=''$lim_start=0$limite=10$browse=0,
                       
$site=0$path=''$relative_script_path '.'$template='',
                       
$templates_links='')
{
///////////////// stuff goes here /////////////////
$timer = new phpdigTimer('html');
$timer->start('All'); 
Keep the template, $t_mstrings variable, and config file the same and give it a whirl.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-07-2004, 10:07 AM   #15
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
It worked! 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.
vinyl-junkie is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
php includes template info 5wayshost Coding & Tutorials 0 12-31-2006 09:59 PM
A simple include in my php template doesn't appear claudiomet How-to Forum 4 08-23-2004 06:35 AM
Creating a .php Template Instead of .html Destroyer X How-to Forum 25 07-29-2004 09:53 PM
PHP and Javascript in phpdig.html template file jayhawk How-to Forum 1 06-17-2004 05:03 PM
PHP includes in Template? jirving How-to Forum 1 09-29-2003 02:37 PM


All times are GMT -8. The time now is 08:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.