Jump to content

Trouble with class not found in append file


Zahari M.
 Share

Recommended Posts

Hi everyone and thanks for reading this!

Feel kind of dumb so I have come to ask for some guidance!

The problem I am having is trying to get the All In One Minify module working in a PW site having selected the default profile during installation. Here's the issue...

The default profile has an append and prepend file arrangement. All the html to generate the page is located inside the _main.php file which is appended to the main template files i.e. home.php and basic-page.php.

When we install the All In One Minify module we need to add this to our <head> section...

<link rel="stylesheet" type="text/css" href="<?php echo AIOM::CSS('css/stylesheet.css'); ?>">

Unfortunately when we do this we get a blank screen! Turning debug on gives us the error...

Error:  Class 'ProcessWire\AIOM' not found (line 41 of /Applications/MAMP/htdocs/pw.dev/site/templates/_main.php) 

So I guess this AIOM class is out of scope and we probably need to use wire() somehow or other? The problem is I don't know how to write it out!

I would be very grateful if someone could show me how we would rewrite the above using wire to get the class in scope. 

Thanks again everyone!

Link to comment
Share on other sites

Looks like you have a namespace issue - I am using AIOM on a PW3 site without any problems - the file compiler is properly taking care of things. That error is coming from the uncompiled version of _main.php though - are you using PW3? Do you have the filecompiler on? Are you manually specifying the ProcessWire namespace?

I am guessing the latter - you are manually specifying the namespace, but AIOM is not namespaced, hence the problem. What happens if you do:

<link rel="stylesheet" type="text/css" href="<?php echo \AIOM::CSS('css/stylesheet.css'); ?>">

Note the backslash to request the class in the global namespace.

  • Like 1
Link to comment
Share on other sites

Hi Adrian!

Great diagnosis there! Yes I was using PW3 latest dev version when trying this.

Adding the backspace fixes the problem Adrian! Thanks for that.

From what I see Adrian, when we install ProcessWire 3 dev version, the basic profile is not namespaced whilst the default profile is namespaced.

As I was using the latest dev version and the default profile Adrian, the template files were already namespaced. I am not too sure if that's what you mean by manually adding the namespace. Also I assume the file compiler is on but I have to admit I don't know how to check if it is on or not!

Anyways, just to clarify Adrian, if we install a fresh pw3 site with the default profile that already has namespaced template files and we then install the AIOM module, what should we do to solve this issue? Just add the backspace as you have done? Or remove the namespaces from the default template files? 

What is your suggestion?

Anyway thanks again for the fix, Adrian. Brilliant!

Cheers!

  • Like 1
Link to comment
Share on other sites

Glad to help Zahari!

I think your question has no definite answer. I do however think that all the profiles should be namespaced, or none namespaced (https://github.com/ryancramerdesign/ProcessWire/issues/1866). I think it is confusing to have a mix.

It is going to be a difficult time with those profiles being namespaced when many modules are still relying on the filecompiler to make them PW3 compatible.

Personally I haven't been namespacing template files yet (or my modules for that matter) because I want PW2 compatibility. But moving forward I expect at some point we'll all be namespacing by default and not relying on the filecompiler. So for the moment, maybe just be aware that when calling a module's class like that, you will need to reference it in the global namespace and all will be good.

You'll notice in that GH issue I linked to that I pointed Ryan to this thread, so maybe he'll also chime in here with his thoughts now that PW3 is getting close to being the stable branch of PW/

Link to comment
Share on other sites

Very thorough of you Adrian to raise the issue in Github!

Your absolutely right in doing so as one would be expecting such a highly favoured / liked module such as AIOM to work with all the profiles in a fresh site install.

That backspace trick of yours sure is really handy to know should we / anyone else run into a similar issue of class not found!

Thanks again mate!

  • Like 1
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...