Jump to content

Recommended Posts

Posted

I'm doing my first steps as module developer and need some help.

Here is my module https://github.com/valieand/GoogleCidCatcher

This module adds hook after login which saves Google Customer ID from browser cookie to user page field 'user_google_cids'.

It seem to work.

But when I try to do the following somewhere in another place:

$module = wire()->modules->get('GoogleCidCatcher');

I get

Error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? (in /var/www/pw/wire/core/Selectors.php line 283)

What is the reason and how to fix it?

P.S. I can't enable debug mode as its a live site. Btw may be there exist another way to debug this error, less painful for live sites? Thanks.

 
Posted (edited)

But when I try to do the following somewhere in another place:

$module = wire()->modules->get('GoogleCidCatcher');
I get
Error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? (in /var/www/pw/wire/core/Selectors.php line 283)
What is the reason and how to fix it?

That syntax doesn't look right to me. If in a template file, you can call your module like this:

$gCatcher = $modules->get("GoogleCidCatcher");

If in a function in a template file:

$gCatcher = wire('modules')->get('GoogleCidCatcher');

If in a module you could use:

$gCatcher = $this->modules->get('GoogleCidCatcher');

P.S. I can't enable debug mode as its a live site. Btw may be there exist another way to debug this error, less painful for live sites? Thanks.

I can't find it now, but there is a way you can load a custom /site/config.php/ e.g. when logged as a superuser, load /site/dev.config.php.

Any reason why you can't debug your module locally?

Edited by kongondo
Posted

@kongondo: 

- syntax is ok. I use it almost everywhere and it works w/o problems. E.g. wire()->pages, etc. Problem should be somewhere else. Could it be connected with autoload/singular module settings? Or use of __constructor()? I can't understand...

- thanks for idea with custom config file for loggedin superuser. Is there any module for that? I'll experiment with it. I guess its a matter of setting $config->debug = true on each request, immediately after $config is initialized. But don't know which hook to use so far...

- I don't use local/dev instance - its too time-consuming to keep things aligned/consistent in two systems.

Posted

It's hard to debug without seeing the whole context. But the error message is clear, there's a problem somewhere with some selector. Problem is without debug on, you cannot really tell which line in what file is causing the error. What does your error.txt file say? 

Posted

error.txt file says the same. So far I've commented this piece of code till I find way to enable debug for superuser only.

Posted

Thank you! Will check and come back later with source of the issue - if not site-specific, it could be useful for other module devs.

Posted

@valan

Looking through your code, I think that the problem could be this line: https://github.com/valieand/GoogleCidCatcher/blob/master/GoogleCidCatcher.module#L195

If your array is empty, you get a strange selector string. Also you are using array_filter without actually filtering anything in the array, not sure how PHP behaves. Normally you'd need to pass a closure as second argument, see: http://php.net/manual/en/function.array-filter.php

Edit: Ok just read the docs, if you omit the closure as second argument when using array_filter, all FALSE entries are removed. :)

  • Like 1
  • 2 weeks later...

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