Jump to content

[SOLVED] Return not returning


stuffradio

Recommended Posts

I have this code that I'm starting to work on. When I try and return it, it won't print anything. When I echo it, everything is echoed.

 

<?php

class Template {

private $theme;
private $themeContents;

        function getTheme() {

        if (!$_GET['theme'] || $_GET['theme'] == "default") {
        ob_start();
$theme = file_get_contents(STYLE_DIR . "default/index.tpl");
$themeContents = ob_get_contents();
        ob_end_clean();
return $themeContents;
}

        }
}

?>

Link to comment
Share on other sites

Theres nothing in your buffer. No reason to be using one either.

 

<?php

class Template {

  private $theme;
  private $themeContents;

  function getTheme() {
    if (!$_GET['theme'] || $_GET['theme'] == "default") {
      return file_get_contents(STYLE_DIR . "default/index.tpl");
    }

  }

}

?>

Link to comment
Share on other sites

You could use output buffering if your template file contained PHP code which had to be evaluated. Then you could use include() or require() instead of file_get_contents(). By doing so there would be output - output which you might have to capture using the output buffering functions.

Link to comment
Share on other sites

I think this is what you meant:

 

$display = new Template();

$display->getTheme();

 

Of course that won't output anything, as I said earlier, file_get_contents() returns a string, it does not output it. Try...

 

<?php

$display = new Template();
echo $display->getTheme();

?>

Link to comment
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.