3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 743 Views |
-
PageID always 0 for shild table

2 September 2010 at 12:56am Last edited: 2 September 2010 12:56am
Hi,
I have a table that will have PageID 0 (zero) it wont insert the ID of the User class <<uses>>
class SomeData extends DataObject
{
public static $db = array(
'Stuff' => 'Varchar(50)',
);public static $has_one = array(
"Page" => "ThaPage"
);}
and
class ThaPage extends SiteTree{
public static $has_many = array(
"SomeDataz" => "SomeData" // ??? do I need this ???
);}
class ThaPage_Controller extends ContentController{
public function doStuff(){
$Stuff = new SomeData();
$Stuff->Stuff = "some stuff to tbl";
$Stuff->write();
}
}The PageID ( <- SiteTree.ID ) will be 0, Do I have to make a method for SomeData that will insert the PageID ?
or im missing something?Thanks
-
Re: PageID always 0 for shild table

2 September 2010 at 1:15am
Hi,
Despite your friendly avatar - let's see if I can help...
I don't think you *need* it, but to use the nice silverstripe functions for accessing relationships, yes it is useful
"SomeDataz" => "SomeData" // ??? do I need this ???
To set the page you could do...
$Stuff = new SomeData();
$Stuff->Stuff = "some stuff to tbl";
$Stuff->setComponent ('Page', $this);
$Stuff->write();or maybe...
$Stuff = new SomeData();
$Stuff->Stuff = "some stuff to tbl";
$Stuff->PageID = $this->ID;
$Stuff->write();...but I am not sure about $this being page object, you might need to use $this->data( ) to get the record to set as the component or get the ID to set directly
-
Re: PageID always 0 for shild table

2 September 2010 at 1:23am
Ahhh.. the $Stuff->PageID = $this->ID worked!!! why to think simple when you can do it complicated :/
Thanks mate!!!
| 743 Views | ||
|
Page:
1
|
Go to Top |


