ryan

Quick guide to the comments system

145 posts in this topic

I'm trying to add a comments section for specific posts on my blog, but ever since adding the comments field to the post template, the admin panel is no longer running the Reno theme, and an attempt to load up access/users throws this:

Error: Uncaught Error: Call to a member function has() on null in /wire/core/Users.php:99
Stack trace:
#0 /wire/core/PagesType.php(265): ProcessWire\Users->loaded(Object(ProcessWire\User))
#1 /wire/core/PagesType.php(395): ProcessWire\PagesType->find('id>0, sort=name')
#2 /wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module(386): ProcessWire\PagesType->getIterator()
#3 /wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module(1680): ProcessWire\InputfieldSelector->setup()
#4 [internal function]: ProcessWire\InputfieldSelector->___render()
#5 /wire/core/Wire.php(374): call_user_func_array(Array, Array)
#6 /wire/core/WireHooks.php(549): ProcessWire\Wire->_callMethod('___render', Array)
#7 /wire/core/Wire.php(399): ProcessWire\WireHooks->runHooks(Object(P (line 99 of /wire/core/Users.php) 

If I remove the comment field from the template, the error persists.

Here is the line in question:

if(!$roles->has("id=$guestID")) $page->get('roles')->add($this->wire('roles')->getGuestRole());

Any ideas?

Update: And now that I've logged out, I can't log in again - entire site is showing an internal server error, which I assume is the same as the above.

Update: No, now the error is this:

2016-12-28 18:32:55	guest	https://blog.rockett.pw/?/	Error: 	Exception: You do not have permission to execute this module - ProcessPageView (in /wire/core/Modules.php line 1236)

?

Share this post


Link to post
Share on other sites
1 minute ago, adrian said:

Looks like you are not alone:

Yeah - I saw those. And no replies!! Also bumped into the issue on the old GH repo, but Ryan is unable to reproduce.

What's interesting is that this only happened when I added the field to the template, and that process took a lot longer than normal...

Share this post


Link to post
Share on other sites

Have you tried to debug the contents of $page that is passed to the loaded() method in the line above?

Share this post


Link to post
Share on other sites
4 minutes ago, adrian said:

Have you tried to debug the contents of $page that is passed to the loaded() method in the line above?

I can't now as guest doesn't have the permission to view a page, by the looks of it. Going to debug modules.php now.

Share this post


Link to post
Share on other sites

I've had a look at the schemas, and it appears everything is fine. In fact, everything matches my development server, except for whatever has been added. In terms of the permissions for ProcessPageView, I can't see anything wrong there either...

Not really sure how to proceed...

Share this post


Link to post
Share on other sites

Any chance it's a third party module? Maybe you could rename the modules db table and the site/modules directory, and clean up the filecompiler cache directory. Maybe also the caches db table?

Share this post


Link to post
Share on other sites
4 minutes ago, adrian said:

Any chance it's a third party module? Maybe you could rename the modules db table and the site/modules directory, and clean up the filecompiler cache directory. Maybe also the caches db table?

It could be, but I doubt it for some reason - everything was running smoothly until I made the field assignment. I have cleared the compiler cache in the directory and the table. Will try those renames now and see what happens.

Share this post


Link to post
Share on other sites

Nah, doing that throws:

Error: 	Uncaught Error: Call to a member function execute() on null in /index.php:55 Stack trace: #0 {main}   thrown (line 55 of /index.php)

That line is part of the PW bootstrap:

echo $process->execute($config->internal);

 

Share this post


Link to post
Share on other sites

I think I'm going to have to merge the new data with my local install manually from the DB and re-upload.

So much for adding comments. Maybe I'll use Disqus instead.

Update: Site is up and running again. Disqus added. Thanks for the help Adrian. Looks like this is something that couldn't have been fixed too easily.

And I do still have the broken site, if you'd like me to try anything. :)

Share this post


Link to post
Share on other sites

Maybe somebody can help me with this. I tried the following code for paginated comments:

 $commentLimit = 2; // comments to display per page
    $start = ($input->pageNum - 1) * $commentLimit;
    $desc = false;
    $selector = "page=$page, sort=-created, start=$start, limit=" . ($commentLimit + 1);

// find the comments. replace "comments" with the name of your comments field
    // I also used the new find command and not the deprecated findComments
    $comments = FieldtypeComments::find("comments", $selector);

in one of my template.php, but it throws an exeption:

Class 'FieldtypeComments' not found

What is wrong?

Share this post


Link to post
Share on other sites
On 28/01/2017 at 5:03 AM, jmartsch said:

in one of my template.php, but it throws an exeption:


Class 'FieldtypeComments' not found

What is wrong?

That's a namespace problem - for some reason your template is not being compiled with the ProcessWire namespace. You can add the namespace...

$comments = ProcessWire\FieldtypeComments::find("comments", $selector);

...but you shouldn't call the find() method statically anyway. The comment block for the deprecated findComments() explains how the find() method should be called:

@deprecated Use $field->type->find($field, $selectorString) instead.

 

1 person likes this

Share this post


Link to post
Share on other sites

Inside /wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module there's a commented section (with @todo comments) for enabling textformatter options, again inside /wire/modules/Fieldtype/FieldtypeComments/Comment.php, textformatter settings are bypassed and comment is presented as is.

When I uncomment these sections, and add a few formatters, they work just fine :).
Is there any reason why these sections are commented out?

Also, is there a way for people to delete their comments?

Share this post


Link to post
Share on other sites

Where to go?

<?php echo $page->comments->render();?>
Quote

Error: Call to a member function render() on a non-object (line 26 of C:\wamp\www\processwire-master\site\assets\cache\FileCompiler\site\templates\basic-page.php) 

 

Share this post


Link to post
Share on other sites
2 minutes ago, Timea said:

Call to a member function render()

Does basic-page template have comments field?

Share this post


Link to post
Share on other sites

Can you post the output of

var_dump($page->comments);

Also, try adding namespace

<?php namespace ProcessWire;

on the first line of basic-page.php

Share this post


Link to post
Share on other sites
var_dump($page->comments); null
Quote

namespace ProcessWire;
Compile Error: Namespace declaration statement has to be the very first statement in the script (line 27 of C:\wamp\www\processwire-master\site\assets\cache\FileCompiler\site\templates\basic-page.php) 

 

 

Share this post


Link to post
Share on other sites

You should place <?php namespace ProcessWire to very first line of the script (to the opening <?php tag), it should look like this

phpstorm64_2017-04-25_20-32-41.thumb.png.f7a1b24e6f5a7915245c8e2ac844ac61.png

1 person likes this

Share this post


Link to post
Share on other sites

Okay, after some remote debugging collaboration with @Timea over Teamviewer, it turns out there was a typo where he/she created/renamed the comments field to Comments and tried to render it using $page->comments where he/she should've used $page->Comments instead. After renaming the field back to lowercase comments, error was fixed :)

3 people like this

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.