Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » i dont understand the write stuff??

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

Page: 1
Go to End
Author Topic: 661 Views
  • Labrar
    Avatar
    Community Member
    4 Posts

    i dont understand the write stuff?? Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: i dont understand the write stuff?? Link to this post

    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?

    661 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.