Jump to content
Pip

Call to a member function add() on null error

Recommended Posts

Hi all, 

I'm tweaking the Login/Register module to enable to automatically create a page for the User Profile. 

See code below: 

				if($input->get('register_created')) {
					$this->message($this->_('Thank you, your account is confirmed and you are now logged in'));
										
				
					$page = $pages->add("blank", "/member/", [
					  'title' => '%s',
					  'name' => '%s'
					]);
				}

Upon completing the confirmation, I get this error: 


Notice
: Undefined variable: pages in
D:\XAMPP\htdocs\food\site\modules\LoginRegister\LoginRegister.module
on line
281


Fatal error
: Uncaught Error: Call to a member function add() on null in D:\XAMPP\htdocs\food\site\modules\LoginRegister\LoginRegister.module:281 Stack trace: #0 D:\XAMPP\htdocs\food\wire\core\Wire.php(380): ProcessWire\LoginRegister->___execute() #1 D:\XAMPP\htdocs\food\wire\core\WireHooks.php(823): ProcessWire\Wire->_callMethod('___execute', Array) #2 D:\XAMPP\htdocs\food\wire\core\Wire.php(450): ProcessWire\WireHooks->runHooks(Object(ProcessWire\LoginRegister), 'execute', Array) #3 D:\XAMPP\htdocs\food\site\assets\cache\FileCompiler\site\templates\access.php(11): ProcessWire\Wire->__call('execute', Array) #4 D:\XAMPP\htdocs\food\wire\core\TemplateFile.php(287): require('D:\\XAMPP\\htdocs...') #5 D:\XAMPP\htdocs\food\wire\core\Wire.php(380): ProcessWire\TemplateFile->___render() #6 D:\XAMPP\htdocs\food\wire\core\WireHooks.php(823): ProcessWire\Wire->_callMethod('___render', Array) #7 D:\XAMPP\htdocs\food\wire\core\Wire.php(450): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array) #8 D:\XAMP in
D:\XAMPP\htdocs\food\site\modules\LoginRegister\LoginRegister.module
on line
281

Fatal Error: Uncaught Error: Call to a member function add() on null in D:\XAMPP\htdocs\food\site\modules\LoginRegister\LoginRegister.module:281
Stack trace:
#0 D:\XAMPP\htdocs\food\wire\core\Wire.php(380): ProcessWire\LoginRegister->___execute()
#1 D:\XAMPP\htdocs\food\wire\core\WireHooks.php(823): ProcessWire\Wire->_callMethod('___execute', Array)
#2 D:\XAMPP\htdocs\food\wire\core\Wire.php(450): ProcessWire\WireHooks->runHooks(Object(ProcessWire\LoginRegister), 'execute', Array)
#3 D:\XAMPP\htdocs\food\site\assets\cache\FileCompiler\site\templates\access.php(11): ProcessWire\Wire->__call('execute', Array)
#4 D:\XAMPP\htdocs\food\wire\core\TemplateFile.php(287): require('D:\\XAMPP\\htdocs...')
#5 D:\XAMPP\htdocs\food\wire\core\Wire.php(380): ProcessWire\TemplateFile->___render()
#6 D:\XAMPP\htdocs\food\wire\core\WireHooks.php(823): ProcessWire\Wire->_callMethod('___render', Array)
#7 D:\XAMPP\htdocs\food\wire\core\Wire.php(450): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array)
#8 D:\XAMP (line 281 of D:\XAMPP\htdocs\food\site\modules\LoginRegister\LoginRegister.module)

This error message was shown because: site is in debug mode. ($config->debug = true; => /site/config.php). Error has been logged.

I've cleared the cache but I'm still getting the error. 😞

Any ideas where I went wrong aside from editing the module?

Thanks

Share this post


Link to post
Share on other sites

Try calling wire('pages') instead of $pages.

  • Like 3

Share this post


Link to post
Share on other sites
On 7/9/2020 at 1:47 AM, elabx said:

Try calling wire('pages') instead of $pages.

Thanks, @elabx! It works! So it'sactually ok to interchange them. 😛

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.

×
×
  • Create New...