Jump to content

Recommended Posts

Ok I have these functions inside a class called TemplateSystem:

 

function loadTemplateFile( $filename )
{
$file = file( $filename );

if( $file == false )
	return null;

$file = implode( " ", $file );
return $file;
}

function parseTemplateFile( $file )
{
$file = str_replace( "%templateheader%", $this->loadTemplateFile( "style/header.html" ), $file );
$file = str_replace( "%templatefooter%", $this->loadTemplateFile( "style/footer.html" ), $file );

//$file = str_replace( "%iecheck%", tmplIECheck(), $file );
return $file;
}

function renderPage()
{
$page = $this->loadTemplateFile( "style/page.html" );
$page = $this->parseTemplateFile( $page );
$page = str_replace( "%templatecontent%", $this->contents, $page );
echo $page;
}

 

Now the way I have posted works exactly as expected. Now if I write the load function like this:

 

function loadTemplateFile( $filename )
{
$file = file( $filename );

if( $file == false )
	return null;


$file = implode( " ", $file );
return $this->parseTemplateFile( $file );
}

 

...and remove the parseTemplateFile from the renderPage function, nothing appears on the screen and the page is compleatly blank. All three functions are in the same class. I have no idea why this is.

 

Thanks,

Ryan

Link to comment
https://forums.phpfreaks.com/topic/66686-functionoop-problem/
Share on other sites

parseTemplateFile call's loadTemplateFile which is fine..

 

but on your change

 

parseTemplateFile call's loadTemplateFile which call's parseTemplateFile

which call's loadTemplateFile which call's parseTemplateFile

 

Inf. Loop,

 

Ohh...shouldn't it only loadTempalateFile if %templateheader% is in the file tho?

Link to comment
https://forums.phpfreaks.com/topic/66686-functionoop-problem/#findComment-334219
Share on other sites

it will get the returned data to check to see if its in their but by then the loop has started..

 

you could try

 

function loadTemplateFile( $filename, $parse=true )
{
$file = file( $filename );
if( $file == false )
return null;
$file = implode( " ", $file );
return ($parse)?$this->parseTemplateFile($file):$file;
}

function parseTemplateFile( $file )
{
$file = str_replace( "%templateheader%", $this->loadTemplateFile( "style/header.html", false ), $file );
$file = str_replace( "%templatefooter%", $this->loadTemplateFile( "style/footer.html", false), $file );
//$file = str_replace( "%iecheck%", tmplIECheck(), $file );
return $file;
}

 

totally untested

Link to comment
https://forums.phpfreaks.com/topic/66686-functionoop-problem/#findComment-334225
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.