17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1247 Views |
-
Querying Database via a Class function from _config.php

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 usingConfig::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. -
Re: Querying Database via a Class function from _config.php

16 May 2008 at 9:41pm Last edited: 16 May 2008 9:44pm
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.
-
Re: Querying Database via a Class function from _config.php

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?
-
Re: Querying Database via a Class function from _config.php

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
| 1247 Views | ||
|
Page:
1
|
Go to Top |



