Jump to:

23545 Posts in 19310 Topics by 2888 members

General Questions

SilverStripe Forums » General Questions » Executing a php script on a certain 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: 1601 Views
  • plm
    Avatar
    Community Member
    9 Posts

    Executing a php script on a certain page? Link to this post

    This may sound like a stupid question, but how do I get a silverstripe page to include php? The documentation says all content is stored in mysite folder, but there's nothing pertinent to the page I've created there. It seems like this should be very simple, but I can't figure it out for the life of me.

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Executing a php script on a certain page? Link to this post

    Your template cannot include PHP. You can include a variable like $Foo and then in your controller (eg Page_Controller) you can define a function Foo() {} which does something. For example

    function Foo() {
    return "Hi";
    }

    Having $Foo in your template will return "Hi";

  • plm
    Avatar
    Community Member
    9 Posts

    Re: Executing a php script on a certain page? Link to this post

    Thanks for your reply. Do I have to do something special to get the templates to link with the .php? I tried doing alot of different things with my TestPage.ss file in themes/templates/tutorial/Layout/ but I can't get it to affect a page of my type TestPage at all.

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Executing a php script on a certain page? Link to this post

    Make sure the temple 'TestPage.ss' is located in the correct theme location. themes/blackcandy/templates/Layout/TestPage.ss should be the path if you're editing the blackcandy theme.

    Also double check to make sure your page type is a TestPage in the CMS and you have run a ?flush=1.

  • plm
    Avatar
    Community Member
    9 Posts

    Re: Executing a php script on a certain page? Link to this post

    Thanks again for the reply. I now can execute the php code by calling the function I defined in the .php from the .ss file. But I cannot get it to output the results under the Content area, instead they output as the very first thing, before the header or menus, no matter where I call the function in the .ss file, how can I do this?

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Executing a php script on a certain page? Link to this post

    This is probably because you are using echo or print. Instead you should use return to pass the value back to the template like my previous example.

  • plm
    Avatar
    Community Member
    9 Posts

    Re: Executing a php script on a certain page? Link to this post

    I followed your advice and have the php working correctly (I think). It appears to generate the correct html code, but the form which it generates fails to send user inputs to the appropriate script. I've gone over it and everything is in the proper directories, but for some reason the same php code that generates a working form wont submit correctly now that I've put it in silverstripe. (The only thing that was changed was echo). Is there some measure I need to take to enable my form?

    1601 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.