Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty Notices verhindern

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
Wstenfuchs
Smarty n00b


Joined: 29 Dec 2011
Posts: 1

PostPosted: Tue Aug 05, 2014 3:47 pm    Post subject: Smarty Notices verhindern Reply with quote

Hallo zusammen,

ich möchte gerne die Anzahl meiner Smarty Notices der folgenden Art entfernen:

Code:

[Tue Aug 05 16:34:47.286792 2014] [:error] [pid 2588:tid 1656] [client 127.0.0.1:59529] PHP Notice:  Undefined index: system in C:\\xampp\\htdocs\\workspace\\sigma\\templates_c\\3508f3ba02fdb270d82ca819567afcf2ab1baeac.file.new_transfer.tpl.php on line 52, referer: http://workspace/sigma/x_abacus/index.php?pageID=202601
[Tue Aug 05 16:34:47.286792 2014] [:error] [pid 2588:tid 1656] [client 127.0.0.1:59529] PHP Notice:  Undefined index: system in C:\\xampp\\htdocs\\workspace\\sigma\\templates_c\\3508f3ba02fdb270d82ca819567afcf2ab1baeac.file.new_transfer.tpl.php on line 53, referer: http://workspace/sigma/x_abacus/index.php?pageID=202601


In diesem Fall wurde versucht auf die Schlüssel eines Array zuzugreifen, wobei das Array nur als leeres Array an das Template übergeben worden ist (die Notices sind also allesamt berechtigt)


Original Template
Code:

<option value="phoenix_rga" {if $form.system == "phoenix_rga"}selected="selected"{/if}>Phoenix_RGA</option>
<option value="unfall" {if $form.system == "unfall"}selected="selected"{/if}>Unfall</option>


Cache-Template (zeile 52 und 53)
Code:

<option value="phoenix_rga" <?php if ($_smarty_tpl->tpl_vars['form']->value['system']=="phoenix_rga") {?>selected="selected"<?php }?>>Phoenix_RGA</option>
<option value="unfall" <?php if ($_smarty_tpl->tpl_vars['form']->value['system']=="unfall") {?>selected="selected"<?php }?>>Unfall</option>


Um mein Problem (Anzeige der Notices im Log) zu lösen, habe ich folgende Threads gefunden:

http://www.smarty.net/forums/viewtopic.php?t=24165

=> Alle Notices gar nicht mehr im PHP Errorlog anzeigen
Code:
$smarty->setErrorReporting(E_ALL ^ E_NOTICE);

[Funktioniert bei mir einwandfrei]
Allerdings behebt das nicht mein Problem (das es den Notice gibt) es unterdrückt nur die Ausgabe

http://www.smarty.net/forums/viewtopic.php?t=20544

=> hier wird erwähnt, dass in Smarty Version 3.2 es einen neuen Umgang mit dieser Art Notices geben soll (Kennt einer den aktuellen Status davon?)

Lösungen

Ich könnte jetzt vor jeder Variable ein isset machen (wird auch im 1. genannten Thread als Lösung angeboten)

Code:

<option value="phoenix_rga" {if isset($form.system) && $form.system == "phoenix_rga"}selected="selected"{/if}>Phoenix_RGA</option>
<option value="unfall" {if isset($form.system) && $form.system == "unfall"}selected="selected"{/if}>Unfall</option>


=> Funktioniert ebenfalls, ist aber nur ein erheblicher Schreibaufwand und trägt nicht wirklich zu einem besser lesbaren Code bei.

Was mein Wunsch / meine Frage wäre:

Kann ich irgendwie beim Zusammenbauen des Templates automatisch ein isset vor jeden Variablenaufruf machen? (Wenn ja, an welche Stelle in Smarty gehörte dieser Codeabschnitt, ich muss gestehen ich blicke noch nicht komplett durch Smarty durch)

Oder gäbe es Gründe (z.B. Performance) die dazuführen, dass von dieser Vorgehensweise dringend abzuraten ist?

Vielen Dank für Eure Zeit und Mühen
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Aug 05, 2014 8:03 pm    Post subject: Reply with quote

Das sauberste wäre natürlich Du würdest den Index im assign definieren.

Code:
$smarty->assign('form',array('system' => null));


alles andere ist Symptombekämpfung.......
Back to top
View user's profile Send private message
TilmP
Smarty Rookie


Joined: 04 Aug 2014
Posts: 8

PostPosted: Tue Aug 12, 2014 2:51 pm    Post subject: Reply with quote

Heisst dass, ich muss alle im {if getesteten Variablen (mit Null) initialisieren und mit ->assign als template Variable zuweisen, um keine Notices von Smarty zu bekommen (durch verschachtelte Templates sind dies bei uns >300)?

In 3.14 akzeptiert Smarty noch einfach bspw. {if $TABLEFILTER} und meckert nicht, wenn die Variable nicht verfügbar ist:
{if $TABLEFILTER}
<script type="text/javascript" src="scripts/tablefilter.js"></script>
{/if}

In 3.19 wird nur
{if isset($TABLEFILTER) && $TABLEFILTER}
<script type="text/javascript" src="scripts/tablefilter.js"></script>
{/if}
akzeptiert.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Aug 12, 2014 4:49 pm    Post subject: Reply with quote

Nochmal: Am error reporting hat sich zwischen Smarty 3.1.14 und 3.1.17 absolut nichts geändert.

Hast Du 3.1.17 auf exakt dem gleichen System laufen?

Ich kann es mir nur so erklären, dass bei 3.1.14 in der php.ini
mit error_reporting = E_ALL & ~E_NOTICE die Warnings ausgeschaltet waren und das dieses bei dem System mit 3.1.17 nicht der Fall ist.

Anstelle den Wert in der php.ini zu ändern kannst Du mit

Code:
$smarty->setErrorReporting( E_ALL & ~E_NOTICE);


das gleiche zur Laufzeit erreichen.

Du könntest in beiden Systemen mal
Code:
phpinfo();

einbauen und die Werte von error_reporting vergleichen.
Back to top
View user's profile Send private message
TilmP
Smarty Rookie


Joined: 04 Aug 2014
Posts: 8

PostPosted: Wed Aug 13, 2014 7:51 am    Post subject: Reply with quote

U.Tews wrote:
Nochmal: Am error reporting hat sich zwischen Smarty 3.1.14 und 3.1.17 absolut nichts geändert.

Hast Du 3.1.17 auf exakt dem gleichen System laufen?


* Es ist das gleiche System mit dem ich Smarty 3.1.14 (hier produktiv im Einsatz) und 3.1.19 teste.
Ich tausche nur das Smarty Verzeichnis innerhalb der Applikation aus (also auch die php.ini ist dieselbe).

* Die Notices, die ich mit 3.1.19 bekomme, haben folgendes Aussehen: "PHP Notice: in file Smarty-3.1.19/sysplugins/smarty_internal_templatebase.php(157) : eval()'d code on line xxx"

* In 3.1.19 habe ich folgende Code-Block in sysplugins/smarty_internal_templatebase.php (um line 157) gefunden, der in 3.1.14 noch nicht vorhaden ist:
Code:

$code = file_get_contents($_template->compiled->filepath);
eval("?>" . $code);
unset($code);
$_template->compiled->loaded = true;
$_template->compiled->isCompiled = true;
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Aug 13, 2014 3:34 pm    Post subject: Reply with quote

Wie ist denn error_reporting in der php.ini Datei aufgesetzt?

Der Kode bei dem die Notice auftritt wird nur durchlaufen wenn ein Template kompiliert wird.

Tritt die Notice auch auf wenn Du die Seite ein 2. mal (ohne Kompilierung) aufrufst?

Unabhängig davon erhalte wie zu erwarten sowohl mit 3.1.14 als auch mit 3.1.19 die E_NOTICE Meldung bei einem undefinierten Array Index sofern sie im error_reporting freigegeben ist.

Mache doch mal vor $smarty->display(...);
Code:
var_dump(ini_get('error_reporting'));

und vergleiche die Werte.

Es muss in der Konfiguration Unterschiede geben....

Setze auch mal $smarty->debugging = true; und schaue ob wirklich in beiden Fällen der Index 'system' von $form undefiniert ist.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Aug 13, 2014 3:39 pm    Post subject: Reply with quote

Der neue Kode wurde im übrigen eingefügt um ein Problem mit dem Zend opcode cache zu umgehen, der sonst Änderungen eines frisch kompilierten Template nicht sah.
Back to top
View user's profile Send private message
TilmP
Smarty Rookie


Joined: 04 Aug 2014
Posts: 8

PostPosted: Wed Aug 27, 2014 9:24 am    Post subject: Reply with quote

* Die (neuen?) Notices werden jetzt in dem Message Handler der Applikation unterdrückt,

* Aber, Ich bekomme jetzt (bei der Nutzung von unseren modalen Fenstern) einen Fatal Error, dass er ein Funktion nicht findet und der User kann nicht weitermachen (Fatal error: Call to undefined function smarty_template_function_modal_input() in C:\xampp\htdocs\compdb\Smarty-3.1.19\sysplugins\smarty_internal_templatebase.php(161) : eval()'d code on line 23),

* Wie gehabt: Die Applikation selbst wurde nicht verändert. Ich habe nur Smarty 3.1.14 gegen 3.1.19 getauscht,

* Woher kommt auf einmal dieser Fatal Error? Änderungen in der Kompilierung? Wie werde ich die Fehler wieder los (betrifft wohl alle modalen Fenster)?

Ein Bsp.
(In \compiled\default)
Bei 3.1.14 bekomme ich
Code:

<?php /* Smarty version Smarty-3.1.14, created on 2014-08-27 11:04:27
         compiled from "styles\default\templates\modal\releases\config_addrelease.html" */ ?>
<?php /*%%SmartyHeaderCode:1768653fd9f1bb4a855-80898542%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
  'file_dependency' =>
  array (
    '7bd5f438137868bd0bbb09622e0891b806a9cf81' =>
    array (
      0 => 'styles\\default\\templates\\modal\\releases\\config_addrelease.html',
      1 => 1382435481,
      2 => 'file',
    ),
  ),
  'nocache_hash' => '1768653fd9f1bb4a855-80898542',
  'function' =>
  array (
  ),
  'has_nocache_code' => false,
  'version' => 'Smarty-3.1.14',
  'unifunc' => 'content_53fd9f1bbbabc4_25270203',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_53fd9f1bbbabc4_25270203')) {function content_53fd9f1bbbabc4_25270203($_smarty_tpl) {?><table>
   <tr><?php Smarty_Internal_Function_Call_Handler::call ('modal_input',$_smarty_tpl,array('input'=>"GENERATION"),'1768653fd9f1bb4a855_80898542',false);?>
</tr>
   <tr><?php Smarty_Internal_Function_Call_Handler::call ('modal_input',$_smarty_tpl,array('input'=>"PRODUCT"),'1768653fd9f1bb4a855_80898542',false);?>
</tr>
   <tr><?php Smarty_Internal_Function_Call_Handler::call ('modal_separator',$_smarty_tpl,array(),'1768653fd9f1bb4a855_80898542',false);?>
</tr>
   <tr><?php Smarty_Internal_Function_Call_Handler::call ('modal_input',$_smarty_tpl,array('input'=>"NAME"),'1768653fd9f1bb4a855_80898542',false);?>
</tr>
   <tr><?php Smarty_Internal_Function_Call_Handler::call ('modal_input',$_smarty_tpl,array('input'=>"STATUS"),'1768653fd9f1bb4a855_80898542',false);?>
</tr>
   <tr><?php Smarty_Internal_Function_Call_Handler::call ('modal_input',$_smarty_tpl,array('input'=>"FREEZEDATE"),'1768653fd9f1bb4a855_80898542',false);?>
</tr>
   <tr><?php Smarty_Internal_Function_Call_Handler::call ('modal_input',$_smarty_tpl,array('input'=>"DELIVERDATE"),'1768653fd9f1bb4a855_80898542',false);?>
</tr>
   <tr><?php Smarty_Internal_Function_Call_Handler::call ('modal_input',$_smarty_tpl,array('input'=>"MCDELIVERY"),'1768653fd9f1bb4a855_80898542',false);?>
</tr>
   <tr><?php Smarty_Internal_Function_Call_Handler::call ('modal_input',$_smarty_tpl,array('input'=>"DESCRIPTION"),'1768653fd9f1bb4a855_80898542',false);?>
</tr>
</table><?php }} ?>


Bei 3.1.19 bekomme ich
Code:

<?php /* Smarty version Smarty-3.1.19, created on 2014-08-27 11:09:45
         compiled from "styles\default\templates\modal\releases\config_addrelease.html" */ ?>
<?php /*%%SmartyHeaderCode:105253fda059e66c53-51329714%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
  'file_dependency' =>
  array (
    '9e24a9b99a93dfb22956d2891b79f220a093fa4b' =>
    array (
      0 => 'styles\\default\\templates\\modal\\releases\\config_addrelease.html',
      1 => 1382435481,
      2 => 'file',
    ),
  ),
  'nocache_hash' => '105253fda059e66c53-51329714',
  'function' =>
  array (
  ),
  'has_nocache_code' => false,
  'version' => 'Smarty-3.1.19',
  'unifunc' => 'content_53fda059ed9c79_69467081',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_53fda059ed9c79_69467081')) {function content_53fda059ed9c79_69467081($_smarty_tpl) {?><table>
   <tr><?php smarty_template_function_modal_input($_smarty_tpl,array('input'=>"GENERATION"));?>
</tr>
   <tr><?php smarty_template_function_modal_input($_smarty_tpl,array('input'=>"PRODUCT"));?>
</tr>
   <tr><?php smarty_template_function_modal_separator($_smarty_tpl,array());?>
</tr>
   <tr><?php smarty_template_function_modal_input($_smarty_tpl,array('input'=>"NAME"));?>
</tr>
   <tr><?php smarty_template_function_modal_input($_smarty_tpl,array('input'=>"STATUS"));?>
</tr>
   <tr><?php smarty_template_function_modal_input($_smarty_tpl,array('input'=>"FREEZEDATE"));?>
</tr>
   <tr><?php smarty_template_function_modal_input($_smarty_tpl,array('input'=>"DELIVERDATE"));?>
</tr>
   <tr><?php smarty_template_function_modal_input($_smarty_tpl,array('input'=>"MCDELIVERY"));?>
</tr>
   <tr><?php smarty_template_function_modal_input($_smarty_tpl,array('input'=>"DESCRIPTION"));?>
</tr>
</table><?php }} ?>
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Aug 27, 2014 5:32 pm    Post subject: Reply with quote

Ein paar grundsätzliche Fragen zu Deiner Applikation:

Benutzt Du Template Inheritance?

Wo sind die Template Functions deklariert? In einem Subtemplate dass mit {include} geladen wird?

Wird Dein Beispiel Template "config_addrelease.html" in einer {nocache} Sektion aufgerufen?
Back to top
View user's profile Send private message
TilmP
Smarty Rookie


Joined: 04 Aug 2014
Posts: 8

PostPosted: Mon Sep 15, 2014 1:35 pm    Post subject: Reply with quote

Ja, es wird sowohl mit {include} als auch mit {extends} bspw. {extends file="common/layout.html"} im Modal-Handling gearbeitet. {function} wird ebenflass benutzt z.B.

Code:
{strip}
{function name=modal_input input=""}
   {$input = strtoupper($input)}
   {if isset($I_{$input})}
      {$input = $I_{$input}}
      {include "common/modal_input.html"}
   {else}
      <td width="20"%><label>{$input}</label></td><td>==Input not defined==</td>
   {/if}
{/function}
{function name=modal_separator}
   <td colspan="{if $MODAL.COUNTER}3{else}2{/if}"><hr></td>
{/function}
{function name=include_same_add replace="_edit"}
   {$path = substr($smarty.current_dir,strlen($STYLE.TEMPLATE_PATH)+1)}
   {$file = str_replace($replace,"_add",$smarty.template)}
   {include "{$path}/{$file}"}
{/function}
{/strip}
{if $LAYOUT.DATEPICKER}
<script type="text/javascript">
// <![CDATA[
   $(function() {
      $(".datepicker").datepicker({
         dateFormat: 'yy-mm-dd', firstDay: 1, showWeek: true,
         showOtherMonths: true, selectOtherMonths: true,
         changeYear: true, yearRange: 'c-1:c+2'
      });
   });
// ]]>
</script>
{/if}


Hier der Call Stack:
( ! ) Fatal error: Call to undefined function smarty_template_function_modal_input() in C:\xampp\htdocs\compdb\Smarty-3.1.19\sysplugins\smarty_internal_templatebase.php(161) : eval()'d code on line 23
Call Stack
# Time Memory Function Location
1 0.1041 334392 {main}( ) ..\modal.php:0
2 0.1068 841008 require( 'C:\xampp\htdocs\compdb\includes\modal.php' ) ..\modal.php:10
3 0.1495 3899440 page->display( ??? ) ..\modal.php:336
4 0.1496 3899472 page->_resolve( ???, ???, ??? ) ..\page.php:150
5 0.1554 4116248 Smarty_Internal_TemplateBase->display( ???, ???, ???, ??? ) ..\page.php:98
6 0.1554 4116344 Smarty_Internal_TemplateBase->fetch( ???, ???, ???, ???, ???, ???, ??? ) ..\smarty_internal_templatebase.php:398
7 0.2761 7310360 content_5416b054913ca9_34143610( ??? ) ..\smarty_internal_templatebase.php:192
8 0.4560 8124360 Smarty_Internal_Template->getSubTemplate( ???, ???, ???, ???, ???, ???, ??? ) ..\smarty_internal_templatebase.php(161) : eval()'d code:67
9 0.4560 8128152 Smarty_Internal_TemplateBase->fetch( ???, ???, ???, ???, ???, ???, ??? ) ..\smarty_internal_template.php:303
10 0.4887 8222464 content_5416b054c5f235_05628120( ??? ) ..\smarty_internal_templatebase.php:19
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP