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.

Archive /

Our old forums are still available as a read-only archive.

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

php


Reply


5 Posts   1991 Views

Avatar
jerome187

Community Member, 5 Posts

29 December 2007 at 6:58am

I need to put some php into one of my .ss files (its a template) how to I tell ss to process it as .php and not .html?

Avatar
jerome187

Community Member, 5 Posts

29 December 2007 at 3:36pm

Someone in #silverstripe helped me figure it out.

Avatar
marikas

Community Member, 24 Posts

30 December 2007 at 11:07am

Hi Jerome187,

Great you learned how to do this. Would you mind sharing the titbit to help other helpless fools like myself? :)

TIA

Avatar
Ingo

Forum Moderator, 801 Posts

5 January 2008 at 9:49pm

to follow up on the request: the underlying principles that silverstripe builds upon generally discourage putting too much logic into templates, thats why we have a intentionally restricted template language that doesn't parse PHP.
PHP-code belongs into the controller or model, which can both be accessed in the template by calling methods on them.

more information:
http://doc.silverstripe.com/doku.php?id=tutorials
http://doc.silverstripe.com/doku.php?id=datamodel
http://doc.silverstripe.com/doku.php?id=templates
http://doc.silverstripe.com/doku.php?id=objectmodel

Avatar
jerome187

Community Member, 5 Posts

6 January 2008 at 4:01pm

pretty much you write a php function in the page controller then call it from your template. Unfortunately this only solved one problem for me, getting the captcha image to display (and validate too) but I ran into another problem when making a form that precesses credit cards via cybersource. Creating the form in php was a huge pain, and I could not even get it working, I could not find out how to change the action to something simple, like action="https:somewhere.com/process.php" I could make the form call a php function when it gets submitted but I did not know how to make php send a form to an address. Also in the form this code was necessary:

<?php
require_once ("HOP.php");
InsertSignature("$ammount", "usd")
?>

I had no idea where to put that... I ended up making the order page outside of ss and using a page to redirect to it. Kinda lame cause its a static page and has to be edited everytime the site is changed from the cms. Does anyone know what I'm talking about and can anyone propose a better solution for this? I like SS, becides not allowing php in the templates... and making the forms, its nice for error checking but.... maybe if I knew how to use them better?

--Jerome