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.

Data Model Questions

SS3 - returning datalist as array always throwing error


6 Posts   1221 Views


21 August 2012 at 10:54am Community Member, 24 Posts

Currently with SS3 I am always getting an error when trying to return a datalist as JSON and since we can't debug with isDev=1 due to a core SS bug and no error is being written to log I can't figure out why the following code is erroring out.

$sql = "CALL get_closest_state(".$lat.",".$long.");";
$results = DB::query($sql);
for ($i = 0; $i < $results->numRecords(); $i++) {
$record = $results->nextRecord();
   $states[] = $record['State'];   
$programs = Program::get()->filter(array('StateID' => $states))->toNestedArray();
return json_encode($programs);

Note in the above if I dump out $states it is a proper array with two strings so I know the SP is running fine. Just for some reason any time I try to query my Program dataobject it always fails. If I remove the ->toNestedArray() and view the var I see it is a datalist but when I try to get any data from that datalist it just errors out.

Any help would be great. I have been seeing many issues with the new SS3 data model where it just does not seem to work even through I am following the api documentation.

Thanks in advance,


21 August 2012 at 10:02pm Forum Moderator, 5511 Posts

Why can't you see the error? Developing without errors is like driving blind, you're doing fine till you hit something sooner or later. Look into making sure you can see errors. (set dev mode in your _config or _ss_environment) or check your php server error log file.

DataList will internally generate SQL, you can see what SQL it'll give out if you output Program::get()->filter(array('StateID' => $states))->sql(). Compare the sql to what you think you should be running. Run it in your db backend, see if that errors out.


22 August 2012 at 12:46am Community Member, 24 Posts

Hi Willr,

I had checked the sql it is correct and when run returns the proper data.

When I set my site to dev mode I am always getting errors of -
[Strict Notice] Declaration of HomePage_Controller::init() should be compatible with that of Page_Controller::init()

Note we extended Page_Controller init to allow the passing of two parameters. All works fine just whenever I switch to dev mode I cannot get these errors to ignore even though nothing is wrong. If I set my php.ini to not log strict it still shows them.

HomePage.php -

class HomePage_Controller extends Page_Controller {
      public function init() {         
         $css = array('file1', 'file2');
         $js = array('file1', 'file2');
         parent::init($css, $js);         

Page.php -

public function init($customCSSFile = null, $customJSFile = null) {
self::loadStyles($customCSSFile, $customJSFile);

So as you can see we are not doing anything out of the ordinary just some standard things that help us control/minify our css and js files etc...

If I try to use ?isDev=1 that just goes into an infinite loop and uses all memory even if I give the site 2GB to use. That is related to bug -

So not really sure what else to recommend. Been developing on silverstripe for 4 years now but the new SS3 ORM just doesn't seem to work like the api docs would assume to let it work.

Anyways, thanks for the response,


22 August 2012 at 7:25pm Forum Moderator, 5511 Posts

Exactly as the error says "Declaration of HomePage_Controller::init() should be compatible with that of Page_Controller::init()". You have to keep the same signature between all the functions.

IMHO rather than passing things through levels of constructors use class properties.

class Page ..

protected $css, $js;

class HomePage

function init() {
$this->css[] = "foo.css";
$this->js[] = "bar.js";



23 August 2012 at 12:38am Community Member, 24 Posts

Hi Willr,

I understand what the error states, my issue is that if I specifically have php not set to log/show 'Strict' warnings. silverstripe is still throwing them. Secondly we had been using this setup since SilverStripe 2.1 and up and only in 3.x versions did it start erroring out... So just not sure why that had changed.

I will work to refactor the code but really still doesn't get to the heart of the issue of when the API logs state that on DataList you can call toNestedArray() and the sql checks out, why would core truly error out...

I'll let you know what I see after I have refactored everything.


23 August 2012 at 6:54pm Forum Moderator, 5511 Posts

I understand what the error states, my issue is that if I specifically have php not set to log/show 'Strict' warnings. silverstripe is still throwing them.

Check SilverStripe doesn't override the error_reporting() somewhere (e.g in _config.php) and your syntax is correct.

I didn't see any other error in your post other than that strict issue, does fixing the strict issue give you another error or a white page?