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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   1175 Views

Avatar
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): http://www.sspaste.com/paste/show/501be687b44ad
Complete code of the CoursePage.php: http://www.sspaste.com/paste/show/501be8ecad0b1

Avatar
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.