3818 Posts in 841 Topics by 527 members
Jump to:If this is your first visit, you will need to register before you can post. However, you can browse all messages below.
| Page: 1 | go to end | Reply | |
| Author | Topic: Querying Database via a Class function from _config.php | 350 views |

15 May 2008 at 9:34pm
Hi,
I would like to shift the theme selection process to a Page in the CMS.
I have the following;
class Config extends Page {
static $db = array(
'Theme' => 'Text',
);
function get_current_theme() {
$result = DataObject::get_one('Config');
return $result->Theme;
}
The function returns the value of Theme if I call $get_current_theme from a template but if I call it from mysite/_config.php using
Config::get_current_theme();
I get the following errors, which I assume are because I am ahead of the class construction of SS.
Warning: ClassInfo::dataClassesFor() no parents for Config in sapphire\core\ClassInfo.php on line 49
Warning: Invalid argument supplied for foreach() in sapphire\core\ClassInfo.php on line 50
Fatal error: DataObject::buildSQL: Can't find data classes (classes linked to tables) for Config in sapphire\core\model\DataObject.php on line 1334
Can I achieve the same DB query using the SQLQuery function? If so how, I can't work out the syntax from the doco or api pages.

16 May 2008 at 9:41pm
AFAIK you can only do
Config::get_current_theme();
if you made get_current_theme() a static method.
See for example: http://theserverpages.com/php/manual/en/language.oop5.static.php
Be aware though that static vars/methods are tied to the class rather than to an instance of it.
Last edited: 16 May 2008 at 9:44pm

17 May 2008 at 8:54am
Dio
Thanks for that.
I can get the get_current_theme() code to run, my issue is querying the Config table for the value of Theme.
At the very least what I want to do is "SELECT * FROM Config" and then get the value of Theme from the 1 row which is returned (as I only have one row..)
But how to do it from my Config.php class function without the errors listed on original post?

26 May 2008 at 9:17pm
just wondering if you go this working, cos i would like to be able to select a theme from inside the cms as well...
if you did could you post the code?
thanx
| 350 views | |||
| go to top | Reply |