5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 4248 Views |
-
How to get the current page ID dynamically?

20 March 2009 at 4:32am
Hi,
How do I extract the current page ID (to $id)?
I would like to do something like this:$contactform = new TreeDropdownField("ContactformID","Contactform","SiteTree");
$contactform->setTreeBaseID($id);
$contactform->setFilterFunction(create_function('$item','return $item->ClassName == "ContactForm";'));
$fields->addFieldToTab("Root.Content.Main",$contactform);This way I would like to retrieve all contactforms that are children of the current page.
If I'm asking something that's impossible: please tell me. Otherwise: give me a clue ;-) -
Re: How to get the current page ID dynamically?

21 March 2009 at 2:13am
You should be able to get the current page's ID with:
$this->ID;
Hope that helps,
Ben -
Re: How to get the current page ID dynamically?

21 March 2009 at 12:23pm
Shame on me... that's just too easy... I should've thought about it myself :$
I didn't, so thanks alot. It worked right away. -
Re: How to get the current page ID dynamically?

23 November 2010 at 12:29am
How do i get the current page id. it doesn seem t work when withing a function
I just seem to get the ID of FlashAdvertChoice tablefunction MyAdverts() {
$adverts = DataObject::get_one("MainFlashAdvert");
$CurrentPageID = $this->ID;
return ($adverts) ? DataObject::get("FlashAdvertChoice", "PageID = $CurrentPageID ", "ID DESC", "") : false;
}.ss
control MyAdverts
$CurrentPageIDend_control
| 4248 Views | ||
|
Page:
1
|
Go to Top |

