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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

ArticlePage Database Problem in Tutorial 2


Go to End


6 Posts   2054 Views

Avatar
rowlf

Community Member, 3 Posts

28 February 2009 at 9:02am

Hi I get the following error when rebuilding the database in tutorial 2 after adding the db fields in the ArticlePage.php class

Building Database
Creating database tables

PageComment
SiteTree
Email_BounceRecord
QueuedEmail
File
Group
LoginAttempt
Member
MemberPassword
Permission
Widget
WidgetArea
Page
GhostPage
ArticleHolder
ArticlePage
Table ArticlePage: created
[Notice] Undefined index: ArticlePage
GET /silverstripe/dev/build?flush=1
Line 352 in C:\wamp\www\SilverStripe\sapphire\core\model\Database.php

Source
343
344 if(!$newTable && !isset($this->fieldList[$table])) {
345 $this->fieldList[$table] = $this->fieldList($table);
346 }
347
348 if(is_array($spec))
349 $specValue=$spec['data_type'];
350 else $specValue=$spec;
351
352 if(is_array($this->fieldList[$table][$field]))
353 $fieldValue=$this->fieldList[$table][$field]['data_type'];
354 else $fieldValue=$this->fieldList[$table][$field];
355
356 if(is_array($spec_orig))
357 $spec_orig=DB::getConn()->$spec_orig['type']($spec_orig['parts']);
358
Trace

Notice: Undefined offset: 0 in C:\wamp\www\SilverStripe\sapphire\dev\Debug.php on line 520

Warning: Invalid argument supplied for foreach() in C:\wamp\www\SilverStripe\sapphire\dev\Debug.php on line 557

Warning: Invalid argument supplied for foreach() in C:\wamp\www\SilverStripe\sapphire\dev\Debug.php on line 557

Warning: Invalid argument supplied for foreach() in C:\wamp\www\SilverStripe\sapphire\dev\Debug.php on line 557

Warning: Invalid argument supplied for foreach() in C:\wamp\www\SilverStripe\sapphire\dev\Debug.php on line 557

Warning: Invalid argument supplied for foreach() in C:\wamp\www\SilverStripe\sapphire\dev\Debug.php on line 557

AAA()
Line A of A
III()
Line I of I
iii()
Line i of i

iii()
Line i of i
iii()
Line i of i

If I comment out the entries for db
<?php
/**
* Defines the ArticlePage page type
*/
class ArticlePage extends Page {
static $db = array(
/* 'Date' => 'Date',
'Author' => 'Text'*/
);
static $has_one = array(
);

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');

return $fields;
}
}

class ArticlePage_Controller extends Page_Controller {

}

?>

Then the error goes away. I'm using the latest svn trunk (http://svn.silverstripe.com/open/phpinstaller/trunk) and wamp on windows xp.
Any ideas as to what's causing this?

Regards,
Martin.

Avatar
Willr

Forum Moderator, 5523 Posts

28 February 2009 at 2:23pm

why are the db entrys commented out? that could be messing with something.

Avatar
rowlf

Community Member, 3 Posts

28 February 2009 at 9:18pm

It's to highlight where I suspect the error is. When the lines are uncommented (as per the tutorial) I get the 'Undefined Index' error, if I comment them out the error goes away. I expect the reason it goes away is that as there are no database fields, it doesn't actually create the ArticlePage table.
Is there any way of debugging the problem?

Avatar
rowlf

Community Member, 3 Posts

28 February 2009 at 10:27pm

After a bit of poking around it looks like if fails in the requireField function of database.php
$this->fieldList[$table] fails as
$this->fieldList["ArticlePage"] doesn't exist even though I get the message
# ArticlePage
# Table ArticlePage: created
in the debug output
hope this helps.

Avatar
mobius

Community Member, 54 Posts

9 March 2009 at 11:33pm

I'm also getting this kind of error when trying to build my own data objects. I'm using svn trunk.

Avatar
mobius

Community Member, 54 Posts

10 March 2009 at 12:12am

I managed to work around this by copying an older version of Database.php that I had.

http://open.silverstripe.com/changeset?old_path=%2Fmodules%2Fsapphire%2Fbranches%2Fnestedurls%2Fcore%2Fmodel%2FDatabase.php&old=72505&new_path=%2Fmodules%2Fsapphire%2Fbranches%2Fnestedurls%2Fcore%2Fmodel%2FDatabase.php&new=72514

shows the difference between the two files. 72514 seems to be quite broken.

(I copied from a site that had nestedurls to one that didn't, but I don't think that is too much of an issue)