change...
$p->ChamberTitle = $do->ChamberTitle;
to...
$p->Title = $do->ChamberTitle;
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
change...
$p->ChamberTitle = $do->ChamberTitle;
to...
$p->Title = $do->ChamberTitle;
Thank you so much Swaiba :)
That was giving me the title of the dataobject instead of the parent page so I tried this:
$p->Title = 'Committee Members';
and it worked. Should be okay, right?
If I had another page with dataobjects would I have to repeat all that code or just add a few lines?
Hi Swaiba,
I've been trying for a while now with no success to repeat this dataobject search fix for another page that uses dataobjects.
I have basically the same set up as the staff section except it has only first and last names.
I've tried repeating the code and changing some relevant info, I've tried adding to the current code but no luck so far.
Could you give me a push in the right direction of what you think I need to do?
I've wrapped the section that needs repeating. basically you do the search again with a different dataobject::get and push the results on to the same "$dosNewResults" that is then combined at the end with the original results from the sitetree
/////////////////////////////////////////////////////////////
// Start Custom
//make our our result set
$dosNewResults = new DataObjectSet();
$arrSearchQuery = explode(' ',$form->getSearchQuery());
$strSearchQuery = '%'.implode('%',$arrSearchQuery).'%';
$dos = DataObject::get('StaffMember',"(ChamberTitle LIKE '".$strSearchQuery."'"."OR Name LIKE '".$strSearchQuery."'"."OR Business LIKE '".$strSearchQuery."'"."OR Phone LIKE '".$strSearchQuery."'"."OR Email LIKE '".$strSearchQuery."') " );
if ($dos) {
$arr = $dos->toArray();
foreach ($arr as $do) {
$p = new Page();
$p->ChamberTitle = $do->ChamberTitle;
$p->URLSegment = '/your-chamber/Staff-members/';;
$p->Content = $do->Description;;
$p->Name = $do->Name;;
$p->Business = $do->Business;;
$p->Phone = $do->Phone;;
$p->Email = $do->Email;;
// $p->SearchTerm = $do->SearchTerm;;
$p->ID = $do->ID;;
$p->Relevance = 1;
$p->CanViewType = 'Anyone';
$dosNewResults->push($p);
}
}
/////REPEATING section above
//this will search another object and push the results on to the same data object set return variable
$dos = DataObject::get('SomeOtherObject',"(ChamberTitle LIKE '".$strSearchQuery."'"."OR Name LIKE '".$strSearchQuery."'"."OR Business LIKE '".$strSearchQuery."'"."OR Phone LIKE '".$strSearchQuery."'"."OR Email LIKE '".$strSearchQuery."') " );
if ($dos) {
$arr = $dos->toArray();
foreach ($arr as $do) {
$p = new Page();
$p->ChamberTitle = $do->ChamberTitle;
$p->URLSegment = '/your-chamber/Staff-members/';;
$p->Content = $do->Description;;
$p->Name = $do->Name;;
$p->Business = $do->Business;;
$p->Phone = $do->Phone;;
$p->Email = $do->Email;;
// $p->SearchTerm = $do->SearchTerm;;
$p->ID = $do->ID;;
$p->Relevance = 1;
$p->CanViewType = 'Anyone';
$dosNewResults->push($p);
}
}
/////REPEATING
//strip out the html from the results and append them to the results
//above - so that the ones with things to buy are first
if ($data['Results']->Count() > 0) {
$arr = $data['Results']->toArray();
foreach ($arr as $do) {
$do->Content = strip_tags($do->Content);
$dosNewResults->push($do);
$dosNewResults->removeDuplicates('URLSegment');
}
}
$data['Results'] = $dosNewResults;
// End Custom
/////////////////////////////////////////////////////////////
Perfect :)
I was close but not close enough,
Thanks again Swaiba - Excellent