17488 Posts in 4473 Topics by 1978 members
| Go to End | Next > | |
| Author | Topic: | 2799 Views |
-
how to use php in theme?

9 September 2008 at 7:37pm
hi,
i´ve a problem. i want to use php-code in my theme (page.ss) but, when if i use php i got only a blank site.but i need php, what can i do? THX!
-
Re: how to use php in theme?

9 September 2008 at 7:51pm
As far as I know, you can't. Create a function in your page controller class that returns the result of your php code, then place $FunctionName in the template
-
Re: how to use php in theme?

9 September 2008 at 7:57pm
You can use StuM's answer if you know what your doing, otherwise you could use an iframe linking to the php script, BUT iframes are the devil, so I'd suggest going with StuM's answer.
-
Re: how to use php in theme?

9 September 2008 at 7:57pm
hey StuM,
thank you for your answer. in which file i must create my function? ;) -
Re: how to use php in theme?

9 September 2008 at 8:02pm
oh no iframes! it´s not a problem for me to create an own function. i only wants to know in which php-file i have to create my own function. thats all ;)
-
Re: how to use php in theme?

9 September 2008 at 8:06pm Last edited: 9 September 2008 8:09pm
In mysite/code/Page.php, if you've created it. If not, create one with the following:
<?php
class Page extends SiteTree {
static $db = array();
static $has_one = array();
}class Page_Controller extends ContentController {
function init() {
parent::init();
}function MyCustomPHPCode()
{
return 'blah blah blah';
}
}save it as mysite/code/Page.php
then place $MyCustomFunction in your template
I think that's the correct way to achieve it, I'm a SS n00b still and that's how I've been doing it
you may have to run yoursite/db/build?flush=1 to get it working
-
Re: how to use php in theme?

9 September 2008 at 8:15pm
oh its doesn´t work. i got no output, whats wrong?
-
Re: how to use php in theme?

9 September 2008 at 8:30pm Last edited: 9 September 2008 8:31pm
Sorry, I put you wrong above, the template variable should be the same as the function name ($MyCustomPHPCode)
I just tried placing php code in the template myself, and it did work(although printed before the html started), so maybe something else is broken
try placing
Director::set_environment_type("dev");
in mysite/_config.php and see if that gives you any hints
| 2799 Views | ||
| Go to Top | Next > |



