Jump to content
BFD Calendar

Search page error

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By snobjorn
      I have a website with multiple content types that I want to be accessible through search. I really like the live search on processwire.com, that sorts content types while typing. I tried to find the code to recreate this, with no luck. Does anyone know if this is jquery, specific jquery plugins, json/xml cached files, and what kind of PHP code is used? Any tip that point me in the right direction would be much apperciated.
      The search result listing seems fairly easy to create with sorting through parameters.
    • By Anders
      I want to allow full text search on my site. There is a very nice solution that comes right out of the box:
      $selector = "title|body~=$q, limit=50"; This works, but to make it even better I would want to give higher weight to pages where the search term occurs in the title, than if it just occurs in the body. After all, a page with the title "Wine from France" is probably the best match for the search "france wine". How do I accomplish this in ProcessWire?
      I can see three possible paths, but I am not very fond of any of them:
      Do a direct SQL query, circumventing the API, along these lines. But I would prefer to abstract away the database layout if at all possible. Use something like ElasticSearch, but to be honest that would be to complicated to set up and maintain in the long run. Make multiple lookups, first for matches in the title, then for matches in the body, and merge and sort in PHP. My suspicion is that this would get complicated quite quickly. For instance, how do you deal with a page that has two of the three search terms in the title and the third in the body? Is there a magic option four I should look into? Or are any of the above options better than the others? Any input is welcome!
    • By jds43
      Hello,
      I have a search page loosely based on Skyscrapers where I'm parsing a selector with options 'beds', 'bathrooms', 'size' fields. It is working well until I select 'Any' after I've run a search. This is where no results are returned (/?beds=&bathrooms=&size=&submit=). I want it to reset and show all results.
      I hope this isn't too vague.
       
    • By sww
      Hey there,
      i am trying to add a kind of "intelligent" search.
      Is there any way to ignore punctuation and extra chars.
      e.g.
      When I type "somebody elses" that I still get the result "SOMEBODY ELSE´S CAR, 2005"
      The problem is the extra ´ … if I don't type it I don't get the result.
      So far I am using %=query (which isn't enough, I know)
      So the idea would be something like that:
      $selector = "sanitize(title|text)%=$q, limit=50";
      I know, it's not gonna work like that … just to illustrate.
      Best,
      Stefan
    • By dandeckr
      Hello!
      I'm making my way through my first encounter with ProcessWire, and I'm very near the end of my tasks! I've searched Google, these forums, and for add-ons, but I haven't found any documentation or reference work for implementing boolean searching in the native CMS? Am I missing a thread, add-on, or docs that can point the way? I'm sure I'm not the first to have a need like this? Thanks in advance! 
×
×
  • Create New...