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.

Archive /

Our old forums are still available as a read-only archive.

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

How to refresh the "page listing" with a search results that has been modify?


Go to End


993 Views

Avatar
goodjoe696

Community Member, 1 Post

6 November 2008 at 8:44am

Edited: 06/11/2008 9:10am

Hi, I'm removing items from a search result using a simple form "SearchForm.php" because i don't want to show files under the "assets/Uploads/" directory. It's deleting correctly. But when the results show up, the page listing number is looking like before removing those unwanted files. So somes result page are showing all 10 results (because all the files are correct) and somes other result page are showing like 6 results (because I delete 4 of them). How can I refresh the page listing with a search results? Thank you in advance!

Here is my code into Page.php under the class "Page_Controller extends ContentController".

function init() {
		parent::init();

		Requirements::themedCSS("layout");
		Requirements::themedCSS("typography");
		Requirements::themedCSS("form");
            Requirements::themedCSS("styles");
            Requirements::themedCSS("navigation");
	}

function SearchForm() {
		$searchText = isset($this->Query) ? $this->Query : '';
		$fields = new FieldSet( new TextField("Search", "", $searchText) );
		$actions = new FieldSet( new FormAction('results', '') );
		return new SearchForm($this, "SearchForm", $fields, $actions);
	}
function results($data, $form) {
		$results = $form->getResults();
		$arrBadResults = array();
		foreach($results as $result) {
			$pos = strpos($result->Filename, "/Uploads/");
			if($pos >= 0) {
		   		array_push($arrBadResults,$result);
		   	}
		}
		$cpt=count($arrBadResults)-1;
		while ($cpt >= 0){
			$results->remove($arrBadResults[$cpt]);
			$cpt--;
		}
		$data = array( 'Results' => $results, 'Query' => $form->getSearchQuery(), 'Title' => 'Résultat de recherche' );
		return $this->customise($data)->renderWith(array('Page_results', 'Page', 'HomePage_results', 'HomePage'));
	}