desbest Posted November 6, 2017 Share Posted November 6, 2017 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. Link to comment Share on other sites More sharing options...
kongondo Posted November 6, 2017 Share Posted November 6, 2017 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... 4 Link to comment Share on other sites More sharing options...
szabesz Posted November 6, 2017 Share Posted November 6, 2017 4 hours ago, desbest said: 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. Hi, A related good to read post: https://processwire.com/talk/topic/13977-custom-php-code-selector/?tab=comments#comment-125688 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now