Mike Rockett Posted December 28, 2016 Share Posted December 28, 2016 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) ? Link to comment Share on other sites More sharing options...
adrian Posted December 28, 2016 Share Posted December 28, 2016 Looks like you are not alone: Link to comment Share on other sites More sharing options...
Mike Rockett Posted December 28, 2016 Share Posted December 28, 2016 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... Link to comment Share on other sites More sharing options...
adrian Posted December 28, 2016 Share Posted December 28, 2016 Have you tried to debug the contents of $page that is passed to the loaded() method in the line above? Link to comment Share on other sites More sharing options...
Mike Rockett Posted December 28, 2016 Share Posted December 28, 2016 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. Link to comment Share on other sites More sharing options...
Mike Rockett Posted December 28, 2016 Share Posted December 28, 2016 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... Link to comment Share on other sites More sharing options...
adrian Posted December 28, 2016 Share Posted December 28, 2016 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? Link to comment Share on other sites More sharing options...
Mike Rockett Posted December 28, 2016 Share Posted December 28, 2016 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. Link to comment Share on other sites More sharing options...
Mike Rockett Posted December 28, 2016 Share Posted December 28, 2016 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); Link to comment Share on other sites More sharing options...
Mike Rockett Posted December 28, 2016 Share Posted December 28, 2016 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. Link to comment Share on other sites More sharing options...
dotnetic Posted January 27, 2017 Share Posted January 27, 2017 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? Link to comment Share on other sites More sharing options...
Robin S Posted January 28, 2017 Share Posted January 28, 2017 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 Link to comment Share on other sites More sharing options...
abdus Posted April 18, 2017 Share Posted April 18, 2017 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? 1 Link to comment Share on other sites More sharing options...
Timea Posted April 25, 2017 Share Posted April 25, 2017 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) Link to comment Share on other sites More sharing options...
abdus Posted April 25, 2017 Share Posted April 25, 2017 2 minutes ago, Timea said: Call to a member function render() Does basic-page template have comments field? Link to comment Share on other sites More sharing options...
Timea Posted April 25, 2017 Share Posted April 25, 2017 Yes. Edit template: basic-page -> add field: comments ok. Link to comment Share on other sites More sharing options...
abdus Posted April 25, 2017 Share Posted April 25, 2017 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 Link to comment Share on other sites More sharing options...
Timea Posted April 25, 2017 Share Posted April 25, 2017 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) Link to comment Share on other sites More sharing options...
abdus Posted April 25, 2017 Share Posted April 25, 2017 You should place <?php namespace ProcessWire to very first line of the script (to the opening <?php tag), it should look like this 1 Link to comment Share on other sites More sharing options...
abdus Posted April 25, 2017 Share Posted April 25, 2017 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 Link to comment Share on other sites More sharing options...
MilenKo Posted September 25, 2017 Share Posted September 25, 2017 Hey everyone. I was reading carefully today almost any post about custom comment listing and forms styling and am super thankful to everyone that shared their knowledge so that a newbie like me could manage to get the comment listing properly applying my custom styles. As far as the the Comment header I have required to post the number of persons that have commented the page, I was facing an issue of singular/plural of the word persons (in my case but could be comment/s etc.) of the count. Looking for a lazy way to achieve that, I found one small function that takes the check for me. If someone is interested to test it, feel free to add this code to your _functions.php or include it in your template code: //Original code: https://stackoverflow.com/questions/4728933/function-switching-between-singular-and-plural function plural( $amount, $singular = '', $plural = 's' ) { if ( $amount === 1 ) { return $singular; } return $plural; } And in my template comments rendering call I used it like this: <?php $com_heading = ''; $count = count($page->comments); $person = ' person' . plural($count); if($count) { $com_heading = "Only " . $count . $person . " commented this recipe. Be the next one!"; } echo $page->comments->render(array( 'headline' => '<h3 class=\'lined\'>' . $com_heading . '</h3>', )); ?> Maybe there is an easier/smarter way to achieve this, but this works fine for my needs and thought someone might find it useful one day... Link to comment Share on other sites More sharing options...
fbg13 Posted September 25, 2017 Share Posted September 25, 2017 1 hour ago, MilenKo said: was facing an issue of singular/plural of the word persons echo (count($page->comments) > 1) ? 'persons' : 'person'; 1 Link to comment Share on other sites More sharing options...
abdus Posted September 25, 2017 Share Posted September 25, 2017 @MilenKo You can just use translation functions for this: echo _n('person', 'persons', $page->comments->count); From the core: // LanguageFunctions.php /** * Perform a language translation with singular and plural versions * * @param string $textSingular Singular version of text (when there is 1 item) * @param string $textPlural Plural version of text (when there are multiple items or 0 items) * @param int $count Quantity of items, should be 0 or more. * @param string $textdomain Textdomain for the text, may be class name, filename, or something made up by you. If omitted, a debug backtrace will attempt to determine automatically. * @return string Translated text or original text if translation not available. * */ function _n($textSingular, $textPlural, $count, $textdomain = null) { return $count == 1 ? __($textSingular, $textdomain) : __($textPlural, $textdomain); } 2 Link to comment Share on other sites More sharing options...
MilenKo Posted September 25, 2017 Share Posted September 25, 2017 @fbg13 & @abdus I really liked your approach as it allows much more simplicity and would avoid bulking up the _function.php . So for the record, here is my code that is fully operational and now shorter and simpler: <?php $com_heading = ''; //Counts the number of comments to list $count = count($page->comments); //Define comment header text $com_heading = "Only $count " . _n('person', 'persons', $page->comments->count) . " commented this recipe. Be the next one!"; //Render comment list echo $page->comments->render(array( //Insert the custom code for the CommentList headline 'headline' => '<h3 class=\'lined\'>' . $com_heading . '</h3>', )); ?> Link to comment Share on other sites More sharing options...
abdus Posted September 25, 2017 Share Posted September 25, 2017 I find using sprintf() for formatting strings to be much cleaner http://php.net/manual/en/function.sprintf.php $count = $page->comments->count; $commentHeading = sprintf("Only %d %s commented on this recipe. Be the next one!", $count, _n('person', 'persons', $count)); 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