Jump to content

Recommended Posts

Posted

Hello,

I've a date field with date input format as follows:

'l, j F Y h:i A'

I've a code that creates calendar of given month & year.

What I need is, I need to find pages having above field and date as per the generated calendar.

From Soma's one post on forum for similar problem, I've written following code, but it's giving error

$this_date_raw = $list_day."/".date('m')."/".date('Y');
			$this_date = date("l, j F Y h:i A", strtotime($this_date_raw));

			
			$day_shows = $pages->find("show_datetime={$this_date}");

			foreach ($day_shows as $ds): $calendar.= "<p>{$ds->title}</p>"; endforeach;
             

Error is as follows:

Error: Call to a member function find() on a non-object (line 54 of D:\wamp\www\ticketees_site\site\templates\calendar.php) 

Thanks in advance.

Posted

Dear nik,

You are awesome!

The given code is indeed part of a function. Is that why PW's $pages->find() not working?

I checked the link you've given, it seems I've to use wire() function but how do I use it for finding pages? can you help with that?

Thanks for your help, I really appreciate it a lot.

And wish you a very Happy Diwali :)

Posted

Yes, $pages is not defined and thus the error. Replace this:

$day_shows = $pages->find("show_datetime={$this_date}");

with this:

$day_shows = wire('pages')->find("show_datetime={$this_date}");

And the same goes for other PW variables listed in http://processwire.com/api/variables/. So $page --> wire('page'), $templates --> wire('templates') and so on.

  • Like 2
Posted

wire('pages') is equivalent to $pages. You use it exactly in the same way:

$day_shows = wire('pages')->find("show_datetime={$this_date}");

Same goes for the other API variables: $page = wire('page'), $input = wire('input'), $session = wire('session'), etc...

Happy Diwali!! (just checked on wikipedia ;))

---------

edit: speedy nik :)

  • Like 2

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
×
×
  • Create New...