Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

2.4 - Adding ParentID filter to a custom search - Please help!

Go to End

2 Posts   922 Views

Nobrainer Web

Community Member, 138 Posts

4 August 2012 at 2:51am

Edited: 04/08/2012 10:09am

Hi guys,

I'm stuck :-( i think it's quite simple, yet i have spend most of my day trying to figure it out.

I have different CourseHolders, that each have several child pages of the type CoursePage.
The CourseHolder lists CoursePages that are children of it self, with the following function (pagination is used)

UPDATE: The code below works - problem is making the CustomSearchCOntext work with the ParentID filter.

public function getGroupCoursesList() {
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
$SQL_start = (int)$_GET['start'];

$CoursesList = DataObject::get(
$callerClass = "Course",
$filter = "ParentID = '". $this->ID . "' AND StartDate > CURDATE()",
$sort = "StartDate ASC",
$join = "",
$limit = "{$SQL_start},10"

return $CoursesList;

I have a custom search on the CourseHolder pages, that should allow the user to filter the list by, city and a date.
The problem is i can not make the custom search context filter the results to only contain children of the current page, it returns all my Courses across all CourseHolder pages.

I have tried adding hidden fields to the form, modifying the query: $query->where('"ParentID" = 11'); editing the $searchCriteria and everything else i could think of, but no luck - PLEASE HELP!

Code that generates the form (in the controller of CourseHolder.php):
Complete code of the CoursePage.php:

Nobrainer Web

Community Member, 138 Posts

6 August 2012 at 9:20pm

I worked around this problem by modifying the working function, to include the filter for City and Time.