Jump to content
Jonathan Lahijani

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

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...