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.

General Questions

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

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

ArticlePage Database Problem in Tutorial 2


Reply

6 Posts   1221 Views

Avatar
rowlf

28 February 2009 at 9:02am Community Member, 3 Posts

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

28 February 2009 at 2:23pm Forum Moderator, 5511 Posts

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

Avatar
rowlf

28 February 2009 at 9:18pm Community Member, 3 Posts

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

28 February 2009 at 10:27pm Community Member, 3 Posts

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

9 March 2009 at 11:33pm Community Member, 54 Posts

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

Avatar
mobius

10 March 2009 at 12:12am Community Member, 54 Posts

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)