Jump to content

To display a repeater item based on ID


SIERRA
 Share

Recommended Posts

Hi,

I would like to display all repeater items in a listing page and would like to navigate to the corresponding detail page page based on the selected repeater item

I am passing the id of  repeater_item like '?id=<?php echo $Admission_Alert->id?>' from the listing page.

Then I am fetching the details as below. But this is not working. Please suggest.

if (isset($_GET["id"]) and $_GET["id"]!="") $id=$_GET["id"];

$alertspage=$pages->get(id); //var_dump($alertspage) is working

echo $alertspage->title //This is not working

Thanks

 

Link to comment
Share on other sites

10 hours ago, SIERRA said:

$alertspage=$pages->get(id); //var_dump($alertspage) is working

Think the issue may be in this line - no $ in front of id. Try:

<?php

if (!empty($input->get->id) // PW way of accessing $_GET
	$id = $sanitizer->int($input->get->id); // Clean it up to ensure it's an integer
           
$alertspage = $pages->get($id); // You can also do $pages->get("id=$id")
if (!$alertspage instance of NullPage) { // ensure the page exists
	echo $alertspage->title;
} else {
	echo "There was a problem retrieving the page with ID $id";
}

 

  • Like 3
Link to comment
Share on other sites

Thanks @SIERRA

Oops! Just re-read my code and noticed a mistake. Should be:

<?php

if (!empty($input->get->id) { // PW way of accessing $_GET
	$id = $sanitizer->int($input->get->id); // Clean it up to ensure it's an integer
           
	$alertspage = $pages->get($id); // You can also do $pages->get("id=$id")
	if (!$alertspage instance of NullPage) { // ensure the page exists
		echo $alertspage->title;
	} else {
	echo "There was a problem retrieving the page with ID $id";
	}
}

Missed the curly braces surrounding the first and last lines 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...