Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

add php on every page


Reply


5 Posts   1938 Views

Avatar
raamklaza

Community Member, 182 Posts

27 February 2009 at 5:24am

I want to add a little bit of code to every page i have.

It has to be php....

I want to add the following, where can i do this so that's on every page?

define("_BBC_PAGE_NAME", "Test");
define("_BBCLONE_DIR", "bbclone/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
if (is_readable(COUNTER)) include_once(COUNTER);

Avatar
Big Bang Creative

Community Member, 92 Posts

27 February 2009 at 5:40am

Try adding your code into your page templates. i.e. Page.ss

Avatar
Carbon Crayon

Community Member, 598 Posts

27 February 2009 at 7:46am

You cannot put PHP into .ss template files.

What exactly are you trying to do with the code? I suspect you want to look at the innit() function in your pages controller, which runs each time the page in initialised.

Avatar
Hamish

Community Member, 712 Posts

27 February 2009 at 9:05am

Yeah BBClone is a stat counter. I used it way back in the day and it was actually quite good for reporting basic stats.

Aram's suggestion should do the trick. Also, you'll want to pass the page name through too. Your page_controller should look a bit like:

   ...
   function init() {
      parent::init();
      define("_BBC_PAGE_NAME", $this->Name);
      define("_BBCLONE_DIR", "bbclone/");
      define("COUNTER", _BBCLONE_DIR."mark_page.php");
      if (is_readable(COUNTER)) include_once(COUNTER);
   }
   ...

Avatar
raamklaza

Community Member, 182 Posts

27 February 2009 at 9:40am

Yes BBClone is a nice statcounter, if i get to work in a function it would be really nice. :)

Hamish the function you wrote seems to work because i get an error from my bbclone program.

Is $this->Name in the form of Home or Weblog or is it home.php and weblog.php ?

I get this msg from my bbclonde installation:
BBClone unknown debug mode:
BBClone isn't able to read its configuration data. This is likely because you embedded BBClone's code snippet into a function. Please use BBClone as suggested in the documentation

The BBClone project is dead atm and the documentation is not accesible anymore....

I hope someone can help me out with the function.

I have the following page_controller which should be correct:
class Page_Controller extends ContentController {
   function init() {
      parent::init();
      
      Requirements::themedCSS("layout");
      Requirements::themedCSS("typography");
      Requirements::themedCSS("form");
      
define("_BBC_PAGE_NAME", $this->Name);
define("_BBCLONE_DIR", "../st/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
if (is_readable(COUNTER)) include_once(COUNTER);      
   }

}