fetchPageDetails (function)

Last updated: Mon, Apr 17, 2023 9:21 am
Return to Knowledgebase

Purpose

Returns information about a page based on id

Location

users/helpers/permissions.php

Parameters

# Parameter Data Type Required Description
1 $id integer Yes specifies the unique identifier of the page for which details are to be fetched

Returns

Data Type Description of Returned Data
array Returns an associative array containing the details of the page with the specified $id, including the id, page, title, private, and re_auth fields. If no page with the specified $id is found, the function returns NULL.

Example

fetchPageDetails(1)

Further Documentation:

The fetchPageDetails() function takes an ID as its parameter and returns the details of a single page from the database based on that ID.

The function first obtains a database instance using the DB::getInstance() method. It then runs a query on the pages table to retrieve the record with the specified id value. The function uses a parameterized query to prevent SQL injection attacks. The query retrieves the id, page, title, private, and re_auth fields for the record matching the specified id.

The function returns the result of the query as an object. If no record with the specified id is found, the function returns null.

Example usage:

Suppose we want to retrieve the details of a page with an id of 5. We can call the fetchPageDetails() function as follows:


$pageDetails = fetchPageDetails(5);

This will retrieve the details of the page with an id of 5 and store the result in the $pageDetails variable. We can then access the properties of the returned object as follows:

$pageId = $pageDetails->id;
$pageTitle = $pageDetails->title;
$pageContent = $pageDetails->page;

This will retrieve the id, title, and page fields from the returned object and store them in the $pageId, $pageTitle, and $pageContent variables, respectively.