Jump to content

Search page error


BFD Calendar
 Share

Recommended Posts

I'm getting an error from sending a search in the search box:

"Notice: Trying to get property of non-object in /home/mekanoinsa/www/site/assets/cache/FileCompiler/site/templates/_func.php on line 45

Fatal error: Uncaught Error: Call to a member function each() on null in /home/mekanoinsa/www/site/assets/cache/FileCompiler/site/templates/_func.php:49 Stack trace: #0 /home/mekanoinsa/www/site/assets/cache/FileCompiler/site/templates/search.php(42): renderNav(Object(ProcessWire\PageArray)) #1 /home/mekanoinsa/www/wire/core/TemplateFile.php(287): require('/home/mekanoins...') #2 /home/mekanoinsa/www/wire/core/Wire.php(380): ProcessWire\TemplateFile->___render() #3 /home/mekanoinsa/www/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___render', Array) #4 /home/mekanoinsa/www/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array) #5 /home/mekanoinsa/www/wire/modules/PageRender.module(514): ProcessWire\Wire->__call('render', Array) #6 /home/mekanoinsa/www/wire/core/Wire.php(383): ProcessWire\PageRender->___renderPage(Object(ProcessWire\HookEvent)) #7 /home/mekanoinsa/www/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___renderPage', Array) #8 /h in /home/mekanoinsa/www/site/assets/cache/FileCompiler/site/templates/_func.php on line 49

This is the code part in _func.php

		// markup for the text
		$programme = "{$item->stu_programme->title}";
			
		$out .= "<div class='list'><div class='listtext'><span class='verdana_18_bold'><a href='$item->url'>$item->title</a></span><br><br><span class='verdana'><b>$programme</b><br>";

	$out .= $item->workshops_list->each(
		"<font color='green'>| {title}</font>"
		);
	
		// if the item has summary text, include that too
		if($item->summary) $out .= "<br><br>$item->summary";	
		
		// end markup for the text
		$out .= "</div>";

Weird, it doesn't happen all the time and I can't figure out what makes the difference....

Link to comment
Share on other sites

What is on line 45? If it is the $programme variable you need to check if it is populated with a Page (?) field.

$programme = count($item->stu_programme) ? $item->stu_programme->title : '';
  • Like 1
Link to comment
Share on other sites

@BFD Calendar You got 

Fatal error: Uncaught Error: Call to a member function each() on null in 

So you have to make sure that the is workshops_list is populated and contains an iterable object that extended from WireArray, so you can use each method on it.

if(count($item->workshops_list)) {
	$out .= $item->workshops_list->each(
		"<font color='green'>| {title}</font>"
		);
}

 

  • Like 2
Link to comment
Share on other sites

7 hours ago, arjen said:

What is on line 45? If it is the $programme variable you need to check if it is populated with a Page (?) field.


$programme = count($item->stu_programme) ? $item->stu_programme->title : '';

We use the search page mostly to check if a student attended the obligatory workshop to use a lasercutter. Every student page has a populated 'stu_programme' field. The search also finds other pages as well of course (tools, machines,....). I finally ended up with this:

if($item->stu_programme) {
$programme = "{$item->stu_programme->title}";
} else {
$programme = "";
}

@Zeka This helps of course, since not every student page has a populated 'workshops_list' field.

So including both solutions passed all my tests for now, thanks!

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...