Jump to content

Functions API enabled but not working


suntrop
 Share

Recommended Posts

It is quite some time since I launched my last PW project and can't remember/find if I forgot something. 

The functions API in my /site/config.php is set to true. I have just installed a blank new PW project. But every call ends with an error.

<?=

var_dump($config->useFunctionsAPI);
page()->get('title');

?>

bool(true) 
Darn… Fatal Error: Uncaught Error: Call to undefined function page() in site/templates/_main.php:15

The config setting is correct, but still it is not working. Did I miss something? I just installed 3.0.165

 

Edit: Just noticed it works fine in template files like basic-page.php and home.php but not in _main.php (which gets appended)

Edited by suntrop
Added more info at the end
Link to comment
Share on other sites

Do you have a correct namespace set in top of your _main.php?

Otherwise you may test in your testpage the following:

<?php
var_dump(function_exists('page'));
var_dump(function_exists('ProcessWire\page'));

 

Link to comment
Share on other sites

Yes, I had set the namespace properly. 

Strange part now, I installed another PW instance, a couple of hours ago, and first thing I tested was the Functions API in a newly created _main.php. It worked. I did a lot of testing and lastly just copied the file itself. That file worked (was just an echo page()->id). I copied the markup again and everything was like before, but it now works.

I have no idea what was wrong with the other file. Just tested with different encodings, BOM, w/out namespace etc. but nothing to reproduce the error.

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