
Trouble Debugging ProcessWire using XDebug + PHPStorm
By
FrancisChung, in General Support
-
Recently Browsing 0 members
No registered users viewing this page.
-
Similar Content
-
By celfred
Hello,
Here's what I'm trying to achieve : I have a textarea field that is frontend editable on any page I want to. If a user with a specific role updates it, I want to tick a checkbox field on the parent page where the textarea resides. So I tried to hook as follows in my ready.php file :
$this->addHookBefore('Fieldtype::savePageField', function(HookEvent $event) { $page = $event->argument[0]; $field = $event->argument[1]; if($this->user->hasRole('teacher')) { $page->alertBox = 1; } // DEBUG HERE (bd($page), l($field)... ???? }); Of course (!) it doesn't work (yet !) but the thing is I have no idea how to debug this since my bd() never triggers. I've tried the 'Event interceptor' of Tracy debugger which helped me setting up my hook. I guess my $page and $field are correct... but how could I go any further ?
The road is long to become a dev (when you're not one 🙂 )...
For further information in case someone wonders : I'd like to set up a textarea that is modified by a user (having a 'player' role, ie 'student'). When front-end modified, I wish it would automatically alert me (the teacher) by ticking a box. So when I log in with my teacher role, I get a list of all textareas I have to read over. When I read/correct/update them (front-end), I would like my hook to automatically untick the box to remove it from my list. In other words, the 'textarea' status should go back and forth according to who modified it last. For the time being, I have managed to make it work with a checkbox that the user has to manually tick/untick, but I've noticed many kids forget to tick the box so they edit their text and I don't get a notice 😞
Thanks if anyone takes time to try and help me on that one !
-
By Robin S
This module is inspired by and similar to the Template Stubs module. The author of that module has not been active in the PW community for several years now and parts of the code for that module didn't make sense to me, so I decided to create my own module. Auto Template Stubs has only been tested with PhpStorm because that is the IDE that I use.
Auto Template Stubs
Automatically creates stub files for templates when fields or fieldgroups are saved.
Stub files are useful if you are using an IDE (e.g. PhpStorm) that provides code assistance - the stub files let the IDE know what fields exist in each template and what data type each field returns. Depending on your IDE's features you get benefits such as code completion for field names as you type, type inference, inspection, documentation, etc.
Installation
Install the Auto Template Stubs module.
Configuration
You can change the class name prefix setting in the module config if you like. It's good to use a class name prefix because it reduces the chance that the class name will clash with an existing class name.
The directory path used to store the stub files is configurable.
There is a checkbox to manually trigger the regeneration of all stub files if needed.
Usage
Add a line near the top of each of your template files to tell your IDE what stub class name to associate with the $page variable within the template file. For example, with the default class name prefix you would add the following line at the top of the home.php template file:
/** @var tpl_home $page */ Now enjoy code completion, etc, in your IDE.
Adding data types for non-core Fieldtype modules
The module includes the data types returned by all the core Fieldtype modules. If you want to add data types returned by one or more non-core Fieldtype modules then you can hook the AutoTemplateStubs::getReturnTypes() method. For example, in /site/ready.php:
// Add data types for some non-core Fieldtype modules $wire->addHookAfter('AutoTemplateStubs::getReturnTypes', function(HookEvent $event) { $extra_types = [ 'FieldtypeDecimal' => 'string', 'FieldtypeLeafletMapMarker' => 'LeafletMapMarker', 'FieldtypeRepeaterMatrix' => 'RepeaterMatrixPageArray', 'FieldtypeTable' => 'TableRows', ]; $event->return = $event->return + $extra_types; }); Credits
Inspired by and much credit to the Template Stubs module by mindplay.dk.
https://github.com/Toutouwai/AutoTemplateStubs
https://modules.processwire.com/modules/auto-template-stubs/
-
By Jarden Black
Hi everyone,
[edit: do not loose your time reading this post, I solved it by disabling cache in the Pages2Pdf module... sorry 😓]
I do not know if I should post on the Pages2Pdf thread or here. Mods, feel free to move the post.
Since three days I am scratching my head to understand a weird thing happening with $session and $config->debug used in conjunction with Pages2Pdf module. For information, I tested it on a fresh install of ProcessWire 3.0.96 with PHP-7.0.28 and Pages2Pdf-1.1.7 (domain: http://session.sites.sek/). I will try to explain what is going on.
What I am trying to achieve :
In a template, I need to set some sessions variables which are then echo'd in the PDF document.
(on the test installation, the basic-page template (page /about/?pages2pdf) serve the PDF, the home and sitemap template set the session variable.)
The problem :
From the template sitemap, I set a variable: $session->setFor('pdf', 'myvar', 'Session set from Sitemap template');
From the template home, I set a variable: $session->setFor('pdf', 'myvar', 'Session set from Home template');
Then in the PDF default template, I echo the session variable: <p>Session: <?= $session->getFor('pdf', 'myvar'); ?></p>
Now I turn ON debug mode ($config->debug = true) :
Then I navigate to "http://session.sites.sek/home/" and the session variable "myvar" is set to "Session set from Home template". Then I navigate to "http://session.sites.sek/sitemap/" and the session variable "myvar" is set to "Session set from Sitemap template". Now I want my PDF document, so I navigate to "http://session.sites.sek/about/?pages2pdf=1" and I get my PDF document with the right session var : "Session set from Sitemap template" For the moment, nothing special happen. Everything work great. We are in debug mode.
Now I turn OFF debug mode ($config->debug = false) :
Then I navigate to "http://session.sites.sek/home/" and the session variable "myvar" is set to "Session set from Home template". Then I navigate to "http://session.sites.sek/sitemap/" and the session variable "myvar" is set to "Session set from Sitemap template". Then I navigate back to "http://session.sites.sek/home/" and the session variable "myvar" is set back to "Session set from Home template". Now I want my PDF document - as expected, the "myvar" should be set to "Session set from Home template" - so I navigate to "http://session.sites.sek/about/?pages2pdf=1" and here the problem happen. Instead of echoing "Session set from Home template" in the PDF document, the phrase "Session set from sitemap" is echo'd (the last value recorded before switching from debug ON).
I made two small screencasts to show the issue :
DEBUG ON (Everything is OK)
DEBUG OFF
I am missing something ? EDIT: YES, you are dumb!
-
By flydev 👊🏻
Hi everyone,
[edit: do not loose your time reading this post, I solved it by disabling cache in the Pages2Pdf module... sorry 😓]
I do not know if I should post on the Pages2Pdf thread or here. Mods, feel free to move the post.
Since three days I am scratching my head to understand a weird thing happening with $session and $config->debug used in conjunction with Pages2Pdf module. For information, I tested it on a fresh install of ProcessWire 3.0.96 with PHP-7.0.28 and Pages2Pdf-1.1.7 (domain: http://session.sites.sek/). I will try to explain what is going on.
What I am trying to achieve :
In a template, I need to set some sessions variables which are then echo'd in the PDF document.
(on the test installation, the basic-page template (page /about/?pages2pdf) serve the PDF, the home and sitemap template set the session variable.)
The problem :
From the template sitemap, I set a variable: $session->setFor('pdf', 'myvar', 'Session set from Sitemap template');
From the template home, I set a variable: $session->setFor('pdf', 'myvar', 'Session set from Home template');
Then in the PDF default template, I echo the session variable: <p>Session: <?= $session->getFor('pdf', 'myvar'); ?></p>
Now I turn ON debug mode ($config->debug = true) :
Then I navigate to "http://session.sites.sek/home/" and the session variable "myvar" is set to "Session set from Home template". Then I navigate to "http://session.sites.sek/sitemap/" and the session variable "myvar" is set to "Session set from Sitemap template". Now I want my PDF document, so I navigate to "http://session.sites.sek/about/?pages2pdf=1" and I get my PDF document with the right session var : "Session set from Sitemap template" For the moment, nothing special happen. Everything work great. We are in debug mode.
Now I turn OFF debug mode ($config->debug = false) :
Then I navigate to "http://session.sites.sek/home/" and the session variable "myvar" is set to "Session set from Home template". Then I navigate to "http://session.sites.sek/sitemap/" and the session variable "myvar" is set to "Session set from Sitemap template". Then I navigate back to "http://session.sites.sek/home/" and the session variable "myvar" is set back to "Session set from Home template". Now I want my PDF document - as expected, the "myvar" should be set to "Session set from Home template" - so I navigate to "http://session.sites.sek/about/?pages2pdf=1" and here the problem happen. Instead of echoing "Session set from Home template" in the PDF document, the phrase "Session set from sitemap" is echo'd (the last value recorded before switching from debug ON).
I made two small screencasts to show the issue :
DEBUG ON (Everything is OK)
DEBUG OFF
I am missing something ? EDIT: YES, you are dumb!
Why it is working with debug mode ON and not vice-versa ?
Is there someone who already spotted this strange behavior ?
Is there a PHP settings which should be modified ?
====================================================
Edit:
I needed to post just to figure myself that Pages2Pdf cache the document when $config->debug is false.
😬😬😬
-
By chrizz
Usually I write modules just for me and my projects because they are more or less individual. Mail Debugger is the first module which might be interested for someone else as well.
https://modules.processwire.com/modules/mail-debugger/
Basically it covers two use cases:
1) Log outgoing emails
2) In debug mode mails are send to a specified email address instead of the original recipient(s)
I checked the compatibility for PW 3+ because unfortunately I don't have any other version for testing currently. Feel free to drop me a comment if the module works also for older PW versions.
-