Jump to:

23461 Posts in 18908 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » add php on every page

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

Page: 1
Go to End
Author Topic: 1796 Views
  • raamklaza
    Avatar
    Community Member
    182 Posts

    add php on every page Link to this post

    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);

  • Big Bang Creative
    Avatar
    Community Member
    92 Posts

    Re: add php on every page Link to this post

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

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: add php on every page Link to this post

    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.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: add php on every page Link to this post

    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);
       }
       ...

  • raamklaza
    Avatar
    Community Member
    182 Posts

    Re: add php on every page Link to this post

    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);      
       }

    }

    1796 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.