MyBB Community Forums

Full Version: How to echo a php function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I needed help in this x.x

Right now i have declared in index.php

include 'a.php';
$b = new me;
$c = $b->hello();

In a.php:
class me {
  public function hello() {
    return "Hello!";
  }
}

So in header template, how to display $c? I tried so many stuff and didnt work. T_T, like {$c}
Where did you declare it? It should be declared below where the templates are declared Wink

Can you send me your CUSTOM coded LINEs & where you declared it?
(2013-03-22, 08:51 AM)Cedric Wrote: [ -> ]Where did you declare it? It should be declared below where the templates are declared Wink

Can you send me your CUSTOM coded LINEs & where you declared it?

I declared in mybb's index.php and the code is exactly like my first post, but i just dont know how to implement $c in mybb template's header

(2013-03-22, 08:51 AM)Cedric Wrote: [ -> ]Where did you declare it? It should be declared below where the templates are declared Wink

Can you send me your CUSTOM coded LINEs & where you declared it?

Updated my first post xD
(2013-03-22, 08:40 AM)Daniel Hyuuga Wrote: [ -> ]I needed help in this x.x

Right now i have declared in index.php

include 'a.php';
$b = new me;
$c = $b->hello();

In a.php:
class me {
  public function hello() {
    return "Hello!";
  }
}

So in header template, how to display $c? I tried so many stuff and didnt work. T_T, like {$c}

Try $b = new me(); (note the parenthesis).
(2013-03-22, 08:59 AM)Seabody Wrote: [ -> ]
(2013-03-22, 08:40 AM)Daniel Hyuuga Wrote: [ -> ]I needed help in this x.x

Right now i have declared in index.php

include 'a.php';
$b = new me;
$c = $b->hello();

In a.php:
class me {
  public function hello() {
    return "Hello!";
  }
}

So in header template, how to display $c? I tried so many stuff and didnt work. T_T, like {$c}

Try $b = new me(); (note the parenthesis).

Nope didn't work. The "$c" needs to be in mybb's template header, something equivalent like {$welcomeblock} in the header file.
Where did you declare it? The header template is evaluated in global.php, you need to put it somewhere in there BEFORE the eval() for the header templates. Smile
Open index.php -> Find this line:

require_once MYBB_ROOT."inc/class_parser.php";

Add below it:

include 'a.php';

Then find ->

$plugins->run_hooks("index_start");

Add below it ->

include 'a.php';
$b = new me;
$c = $b->hello();
$e = $ c;

Now go to index template & try to use {$e}. Should work. If not, try placing the parentheses next to 'me'.
(2013-03-22, 09:24 AM)Cedric Wrote: [ -> ]Now go to index template & try to use {$e}. Should work. If not, try placing the parentheses next to 'me'.

OP wants to use it in the header template.

(2013-03-22, 08:40 AM)Daniel Hyuuga Wrote: [ -> ]So in header template, how to display $c? I tried so many stuff and didnt work. T_T, like {$c}

Open up global.php and find (around line 523):

// Set up some of the default templates
eval("\$headerinclude = \"".$templates->get("headerinclude")."\";");
eval("\$gobutton = \"".$templates->get("gobutton")."\";");
eval("\$htmldoctype = \"".$templates->get("htmldoctype", 1, 0)."\";");
eval("\$header = \"".$templates->get("header")."\";");

Add before:

include 'a.php';
$b = new me; // Change to me() if it still doesn't work.
$c = $b->hello();
Oh sorry I did not read that you wanted to display it in Header template. My code will display it only in Index.php page Wink

Follow seabody's code Big Grin
Pages: 1 2