21288 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1192 Views |
-
Executing a php script on a certain page?

22 October 2010 at 6:10am
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.
-
Re: Executing a php script on a certain page?

22 October 2010 at 5:41pm
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";
-
Re: Executing a php script on a certain page?

23 October 2010 at 11:42am Last edited: 23 October 2010 11:43am
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.
-
Re: Executing a php script on a certain page?

23 October 2010 at 4:20pm
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.
-
Re: Executing a php script on a certain page?

26 October 2010 at 5:40am
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?
-
Re: Executing a php script on a certain page?

26 October 2010 at 9:17am
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.
-
Re: Executing a php script on a certain page?

28 October 2010 at 8:35am
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?
| 1192 Views | ||
|
Page:
1
|
Go to Top |


