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

i dont understand the write stuff??


Go to End


2 Posts   1471 Views

Avatar
Labrar

Community Member, 4 Posts

24 January 2009 at 4:14am

Okay. I,ve read some Tutorials to build Silverstripemodules.
But now i want to try a simple code and it wont work

okay code on testDbase.php

<?php
class testDbase extends DataObject{
static $db=array("Field1"=>"Varchar","Field2=>"Varchar");
}
?>

When i build this, everthing will be created fine. Table named "testDbase" with those Fields
Now i try to write into this table with a simple testcode in a other php file called text.php

<?php
require("testDbase.php"); //of course i also require all the other needed classes like DataObject, DB and so on....

$test=new testDbase();
$test->Field1="Test";
$test->Field2="Field2";
$test->write();

?>

Of course an error occours with "Call to a member function manipulate() on a non-object" becaus $test is an Object but $test->Field1 and $test->Field2 arent.

So. How can i solve that?

Avatar
Willr

Forum Moderator, 5523 Posts

25 January 2009 at 3:18pm

You dont need to require anything. If you code is in mysite/code SilverStripe auto loads all your PHP class's. So just having

$test = new testDbase();
$test->Field1 = "Test";
$test->write();

Will work fine. Is your other text.php file a SilverStripe class?