Jump to content

Call to a member function httpUrl() on null when called inside a function?


Recommended Posts

Posted

When I use the following code I get an error.

<?php
function test(){
    return $page->httpUrl();
    // return $wire->page->httpUrl();
}
$test = test();
echo $test; 

I get this error.

Quote

Error:     Call to a member function httpUrl() on null

How do I fix it? How do I get the current page's url inside a function? The function is being stored on the same template file of the page being displayed.

Posted

There's something called function scope in PHP. In a hurry, please Google forums for more info. For now, use:

wire('page');
wire('pages');
wire('input');
// etc...

 

  • Like 4

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