e107
e107 copied to clipboard
[Bug]: Messages are messed when using e107 debug codes
What e107 version are you using?
v2.3.3, Latest Github version (just updated)
Bug description
If i try to use messages in my plugin, like this:
$msg = e107::getMessage();
require_once(HEADERF);
...
if (!e107::isInstalled('philcat'))
{
$msg->addwarning(LAN_PHILLIS_09);
if (ADMIN == TRUE) {
e107::lan('phillis',"admin", true);
$msg->adderror(PHILLISLAN_19);
}
}
...
if ($msg->hasMessage()) {
echo $msg->render();
require_once(FOOTERF);
exit;
}
and if i try to debug the page with the e107 debug codes in the url, my page is not displayed, as per my code, it has messages and exits.... If i disable the e107 debug codes, it all goes right....
How can i use warning and error messages in my plugin without having this issue?
How to reproduce
Try to use my above code (with some changes) inside a plugin, and test with and without the e107 debug codes in the page url....
Expected behavior
I expected the e107 debug messages no mix with plugins messages....
What browser(s) are you seeing the problem on?
Firefox
PHP Version
PHP 7.4
Yes, it works this way - not a big problem, just remove ?[debug=basic+] from URL and refresh page (debug mode is still on) - related to a problem with URL parameters and SEF URL (regex).
@Jimmi08 Ok, i understand it works this way, but i have a big problem if i want to show error messages for my plugin in the frontend. For instance, with my code, if i got the debug activated, it always has messages, and the script simply exits, but it shouldn't exit, because messages are not from the script...
If i set debugging off, it works like it should, no exit.... But of course, if i have a message in my plugin, it stops and exits....
What i'm doing wrong here?
P.S.: Just a remark, the simple removal of the ?[debug=basic+] from URL doesn't work, if i remove it, debug is still on, even without that in the URL. I have to put ?[debug=off!] on the URL to force debug off.... How i miss the Firefox plugin....
@Jimmi08 Ok, i understand it works this way, but i have a big problem if i want to show error messages for my plugin in the frontend. For instance, with my code, if i got the debug activated, it always has messages, and the script simply exits, but it shouldn't exit, because messages are not from the script...
If i set debugging off, it works like it should, no exit.... But of course, if i have a message in my plugin, it stops and exits....
What i'm doing wrong here?
P.S.: Just a remark, the simple removal of the ?[debug=basic+] from URL doesn't work, if i remove it, debug is still on, even without that in the URL. I have to put ?[debug=off!] on the URL to force debug off.... How i miss the Firefox plugin....
All debug settings were moved to the admin area, I suppose you have still browser extension like me, so setting debug on frontend causes this.
Just a remark, the simple removal of the ?[debug=basic+] from URL doesn't work, if i remove it, debug is still on
yes, that was the point. So your URL is not wrong and your messages work.
but it shouldn't exit, because messages are not from the script...
check e_DEBUG constant , and only if it is true and defined, echo messages (or add messages) - there is a lot of example of this constant in the code. Not sure if I got you right, because why it shouldn't exist? You are rendering them in your code.
You are probably mixing message and debug handlers.
@Jimmi08 I don't have the debug extension
As far i see it, it's because i'm using the $msg
variable, i see some plugins use messages with the $mes
variable, maybe because not to mix front end messages with debug or core messages...
I'll give it a shot and try it...
Not Needed:
if ($msg->hasMessage()) {
echo $msg->render();
require_once(FOOTERF);
exit;
}
Simplify:
if (!e107::isInstalled('philcat')){
$msg = e107::getMessage();
$msg->addwarning(LAN_PHILLIS_09);
if (ADMIN == TRUE) {
e107::lan('phillis',"admin", true);
$msg->adderror(PHILLISLAN_19);
}
require_once(HEADERF);
require_once(FOOTERF);
exit;
}
require_once(HEADERF);
// do the rest of your page as normal...
require_once(FOOTERF);
exit;
@Vodhin That will work, but if i have more conditions to set warning messages, it will be little bit redundant with the code....
Well, i think i catch the bug.....
For instance, if i do
$msg = e107::getMessage();
...
e107::lan('phillis',"front", true);
...
require_once(HEADERF);
...
if (!e107::isInstalled('philcat'))
{
$msg->addwarning(LAN_PHILLIS_09);
if (ADMIN == TRUE) {
e107::lan('phillis',"admin", true);
$msg->adderror(PHILLISLAN_19);
}
}
...
if ($msg->hasMessage()) {
echo $msg->render();
require_once(FOOTERF);
exit;
}
my plugin works like a charm even under debugging....
But if i do
$msg = e107::getMessage();
...
require_once(HEADERF);
...
e107::lan('phillis',"front", true);
...
if (!e107::isInstalled('philcat'))
{
$msg->addwarning(LAN_PHILLIS_09);
if (ADMIN == TRUE) {
e107::lan('phillis',"admin", true);
$msg->adderror(PHILLISLAN_19);
}
}
...
if ($msg->hasMessage()) {
echo $msg->render();
require_once(FOOTERF);
exit;
}
my script simply stops without any warning under debugging....
Anyone has this same issue???
The LAN files need to be loaded before HEADERF
By the way, You can use HTML in the message
$err = array();
$err[0] = LAN1;
$err[1] = LAN2;
if(count($err) > 0){
if(count($err) > 1){
$errtxt = ‘<ul>’;
foreach($err as $k=>$v){
$errtxt .= ‘<li>’.$v.’</li>’;
}
$errtxt .= ‘<\ul>’;
else{
$errtxt = $err[0];
}
$msg->adderror($errtxt);
}
this will render a bullet list. Use whatever HTML you like.
The LAN files need to be loaded before HEADERF
@Vodhin Not quite....
require_once(HEADERF);
if (!e_QUERY && !(e107::getmenu()->isLoaded("philcat"))) {
$msg->addwarning(LAN_PHILCAT_05);
if (ADMIN == TRUE) {
e107::lan('philcat',"admin", true);
$msg->adderror(PHILCATLAN_72);
}
}
On this code, if all ifs are true, the philcat admin lan is correctly loaded.... and the error messages are correctly rendered...
But if you do like my example before, it doesn't work.
Furthermore, if i move the require_once(HEADERF);
to the end of the files, it also breaks the page....
Real weird bug...