17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 890 Views |
-
Form Errors - Trying to get property of a non-object

1 July 2008 at 5:18pm
Hello!
The below code throws two errors which I am having trouble with. The first is in the GetEntrant function. If I have the $data and $form variable defined in the circle brackets - I get an error saying "FATAL ERROR: Missing argument 2 for DrawPrizePage_Controller::GetEntrant()" for both the $data and $form variable.
The second and more important "problem" I have is getting the value from a database object. I am trying to get the MemberDataID value into a variable, from the Competitions table. It is commented in the code below.
class DrawPrizePage_Controller extends Page_Controller {
function Form() {
return new Form($this, "Form",
new FieldSet(
new TextField("CompID", "Competition Page ID")
),
new FieldSet(
new FormAction("GetEntrant", "Draw Winners!")
));
}
function GetEntrant($data, $form) {
$CompID = $this->data['CompID'];
$GetEntry = DataObject::get_one("Competition", "CompetitionPageID='{$CompID}'");
$WinnersDetails = DataObject::get_one("Member", "ID='{$GetEntry->MemberDataID}'"); // How do I get the value for the MemberDataID column which is called in $GetEntry above?
return $WinnersDetails;
}
-
Re: Form Errors - Trying to get property of a non-object

7 July 2008 at 3:01pm
Hi subvert,
If your Competition object has a has_one relationship like this:
static $has_one = array(
"MemberData" => "Member",
);Then you should be able to access the related member's ID by using $GetEntry->MemberDataID, as you have.
Can you post some more information about what errors you are getting - I assume that the code you've posted doesn't work as-is?
PS: $CompID has a SQL-injection vulnerabililty, since $data["CompID"] is set by the browser. Use Convert::raw2sql().
| 890 Views | ||
|
Page:
1
|
Go to Top |


