I am trying to setup a way to output a URL from a dropdown containing the locals site's pages (sitetree). The dropdown works and outputs an id, which is fine, but I cannot seem to select from the database with this ID correctly.
I added the sitetree dropdown to a tab (works fine)
$fields->addFieldToTab('Root.Content.Link', new TreeDropdownField("NewLink", "Page to link to", "SiteTree"));
Since the sitetree dropdown returns a number, I used an Int field
static $db = array(
'NewLink' => 'Int'
);
I created a LinkFromID function in the controller class (As discussed in a previous thread)
class HomePage_Controller extends Page_Controller {
function LinkFromID($id){
$thisPage = DataObject::get_by_id("Page",$id);
return $thisPage;
}
}
When I pass a number to the LinkFromID function, a page shows... but when I attempt to use the NewLink variable, I get an error saying that the variable is not a number.
Works:
<% control LinkFromID(5) %>
$Link
<% end_control %>
Don't work:
<% control LinkFromID(NewLink) %>
$Link
<% end_control %>
Am I passing the variable incorrectly? The variable can be output, and it shows a number. I even attempted to cast the variable as an Int and that doesn't work. Any help would be much appreciated!