- concrete5 Cookbook
- David Strack
- 137字
- 2021-08-13 16:15:57
Getting a page's ID
Developers will often need to know a page's ID, especially when relating pages to other database objects (such as a blog post or calendar event). In this example, we will load the /about
page that we've been working with and get its ID.
Getting ready
Please make sure the /about
page exists in your instance of concrete5. Feel free to modify the code in this recipe if that page does not exist.
How to do it...
The steps for getting a page's ID are as follows:
- Open
/config/site_post.php
in your code editor. - Load the
Page
object by its path.$page = Page::getByPath('/about');
- Get the page's ID.
$id = $page->getCollectionId();
- Dump the contents of the
$id
variable to see what the ID is.my_debug($id);
See also
- The Getting a page by its path recipe