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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

***SOLVED***Staff Section without individual pages?


Go to End


21 Posts   3504 Views

Avatar
swaiba

Forum Moderator, 1899 Posts

1 October 2011 at 4:40am

change...

$p->ChamberTitle = $do->ChamberTitle;

to...

$p->Title = $do->ChamberTitle;

Avatar
ambient

Community Member, 130 Posts

1 October 2011 at 5:00am

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?

Avatar
ambient

Community Member, 130 Posts

4 October 2011 at 4:23am

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?

Avatar
swaiba

Forum Moderator, 1899 Posts

4 October 2011 at 5:00am

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 
/////////////////////////////////////////////////////////////

Avatar
ambient

Community Member, 130 Posts

4 October 2011 at 5:15am

Perfect :)

I was close but not close enough,

Thanks again Swaiba - Excellent

Go to Top