Jump to content

Fatal error: Uncaught Error: Call to a member function get() on null.


Jonathan Lahijani
 Share

Recommended Posts

<?php namespace ProcessWire;
class MyCoolModule extends WireData implements Module, ConfigurableModule {

	public function __construct() {
	    $this->myvar = $this->wire('pages')->get(2)->name; // problematic for some reason
	}

I have the above code in my module.  However it throws this error: Fatal error: Uncaught Error: Call to a member function get() on null.

Why is this the case?

Link to comment
Share on other sites

  • 2 weeks later...

Could you replacing the line with this:

$this->myvar = $this->pages->get(2)->name; // problematic for some reason

I have a note in my Processwire notes that say's

--Extend WireData to access API variables using $this->page instead of calling wire() function every time. It also lets us get module settings directly using $this->someSetting.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...