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

Feeddatei mit Smarty erzeugen

 
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
Chris_B
Smarty Rookie


Joined: 24 Oct 2013
Posts: 6

PostPosted: Thu Oct 24, 2013 1:22 pm    Post subject: Feeddatei mit Smarty erzeugen Reply with quote

Hi,

ich habe heute mit Smarty angefangen und stehe noch gewaltig auf dem Schlauch.

Ich wollte zuerst mal mit Smarty den Export meiner Produktdatei vereinfachen.
Die Beschreibung wie die datei aufgebaut wird steht allerdings in einer Datenbank und der Feldinhalt sieht so aus

<product>
<aid>{Product_id_cat}</aid>
<name>{Product_title}</name>
<desc>{Product_desc}</desc>
<price>{Product_price}</price>
<link>{Product_deeplink}</link>
<brand>{Product_brand}</brand>
<mpnr>{Product_brandItemid}</mpnr>
<shop_cat>{Product_category}</shop_cat>
<image>{Product_mainimage}</image>
<dlv_time>{Product_deliverytime}</dlv_time>
<dlv_cost>{Product_deliverycost}</dlv_cost>
</product>


und wird in der der variable $body gespeichert.

Code:
$smarty->assign("Product_id",$intItemID);
 $smarty->assign("Product_id_cat",$id_cat);
 $smarty->assign("Product_desc",$strProductDescription);
 $smarty->assign("Product_price",$strProductprice);
 $smarty->assign("Product_original_price",$strProductoprice);
 $smarty->assign("Product_color",$strProductcolor);
 $smarty->assign("Product_labels",$labels);
 $smarty->assign("Product_groessen",$groessen);
 $smarty->assign("Product_startdate",$startdatum);
 $smarty->assign("Product_link",$link);
 $smarty->assign("Product_deeplink",$deeplink);
 $smarty->assign("Product_brand",$strProducerName);
 $smarty->assign("Product_brandItemid",$brandItemID);
 $smarty->assign("Product_mainimage",$pic1);
 $smarty->assign("Product_main_category",'Bekleidung & Accessoires > Schuhe');
 $smarty->assign("Product_category",$strProductStyle.' &gt; '.$strProductcattwo);
 $smarty->assign("Product_category1",$strProductcatone);
 $smarty->assign("Product_category2",$strProductcattwo);
 $smarty->assign("Product_category3",$strProductcattree);
 $smarty->assign("Product_deliverytime",'sofort');
 $smarty->assign("Product_gender",$gender);
 $smarty->assign("Product_age_group",$age_group);
 $smarty->assign("Product_ordernr",$LinkOrderNr);
 $smarty->assign("Product_deliverycost",'0.00 EUR');
 $smarty->assign("Product_material",$strProductmaterial);


Meine Frage:

Wie greife ich auf $body anstelle auf ein template zu?

Gruß
Christian
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Oct 24, 2013 10:12 pm    Post subject: Reply with quote

1. Die Variablen im Template bzw. Deiner Datenbank werden über $name angesprochen.


Code:
<product>
<aid>{$Product_id_cat}</aid>
<name>{$Product_title}</name>
<desc>{$Product_desc}</desc>
<price>{$Product_price}</price>
<link>{$Product_deeplink}</link>
<brand>{$Product_brand}</brand>
<mpnr>{$Product_brandItemid}</mpnr>
<shop_cat>{$Product_category}</shop_cat>
<image>{$Product_mainimage}</image>
<dlv_time>{$Product_deliverytime}</dlv_time>
<dlv_cost>{$Product_deliverycost}</dlv_cost>
</product>


$output = $smarty->fetch("string:$body");
bzw
$output = $smarty->fetch("eval:$body");

Siehe http://www.smarty.net/docs/en/resources.string.tpl
Back to top
View user's profile Send private message
Chris_B
Smarty Rookie


Joined: 24 Oct 2013
Posts: 6

PostPosted: Fri Oct 25, 2013 12:42 pm    Post subject: Fehler Reply with quote

Ich bekomme

Notice: Undefined index: Product_title in C:\wamp\www\shop\templates_c\f860727747149a9e2e59063f9db4d8dc7566667f.string.php on line 39

und

Notice: Trying to get property of non-object in C:\wamp\www\shop\templates_c\f860727747149a9e2e59063f9db4d8dc7566667f.string.php on line 39
Back to top
View user's profile Send private message
Chris_B
Smarty Rookie


Joined: 24 Oct 2013
Posts: 6

PostPosted: Fri Oct 25, 2013 12:53 pm    Post subject: Reply with quote

Alles klar und zurück.

Product_title war nicht deklariert.

Gruß
Christian
Back to top
View user's profile Send private message
Chris_B
Smarty Rookie


Joined: 24 Oct 2013
Posts: 6

PostPosted: Sat Oct 26, 2013 8:31 pm    Post subject: Es klappt Reply with quote

Code:
$output = $smarty->fetch('eval:'.$arrFeed->body);
fwrite($datei_handle,$output."\n");

mit fwrite schreibe den output in eine Datei.

Bei meinen Versuchen hatte ich immer nur 10 Datensätze geschrieben.
Jetzt wollte ich alle Datensätze schreiben und das sind etwas über 6000.

Doch da erhale ich nach 10 sek. einen SERVER ERROR 500.

Wenn ich mit meiner alten Methode ohne Smarty mache funktioniert es.

Muss ich mit Smarty etwas berücksichtigen?


Gruß
Christian
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sun Oct 27, 2013 7:41 am    Post subject: Reply with quote

Ich nehme an Du benutzt dafür eine Schleife.
eval: übersetzt jedes mal das template auch wenn sich $arrFeed->body gar nicht geändert hat. Dadurch läufst Du vermutlich in ein memory limit.

Ich würde $output = $smarty->fetch('string:'.$arrFeed->body);

Überprüfe sonst den apache und PHP errorlog.
Back to top
View user's profile Send private message
Chris_B
Smarty Rookie


Joined: 24 Oct 2013
Posts: 6

PostPosted: Sun Oct 27, 2013 8:24 am    Post subject: Reply with quote

Ja, ich gehe in schleife die Datensätze durch.

Fatal error: Out of memory (allocated 47448064) (tried to allocate 40961 bytes) in /homepages/20/d76069802/htdocs/schuhwelt/shop/include/smarty/libs/sysplugins/smarty_internal_templatebase.php on line 174

Wobei der Punkt wo es aussteigt immer unterschiedlich ist.

Ich habe versucht mit define('MEMORY_TO_ALLOCATE','100M');
aber wo nicht genug ist kann nicht mehr herausgeholt werden.

Irgendeine Idee, wie ich den Speicherverbrauch senken kann?

Gruß
Christian
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sun Oct 27, 2013 11:15 am    Post subject: Reply with quote

Hast Du ('string:'.$arrFeed->body); benutzt?

Die string: Resource erzeugt nur einmalig für unterschiedliche Templates Kode.
Back to top
View user's profile Send private message
Chris_B
Smarty Rookie


Joined: 24 Oct 2013
Posts: 6

PostPosted: Sun Oct 27, 2013 2:56 pm    Post subject: Reply with quote

Oh Mann!

Es sind immer die eigenen Fehler die man als allerletztes sieht!

Ich hatte in der Schleife immer noch $smarty = new Smarty;

Das war zuviel des guten.

Jetzt geht es ohne einen Server Error.

Anderes Problem mit dem Feed.
Code:
{if $Feed.rang eq '1'}
{strip}
{$Product_deeplink};
{$Product_title|regex_replace:"/[;]/":""|strip_tags|strip|truncate:80:"...":true} {$Feed.ordernr|trim|regex_replace:"/[ ]/":""};
{$Feed.price};
{assign var="ergebniss" value="Schuhe>`$Feed.categorytxt1`>`$Feed.categorytxt2`>`$Feed.categorytxt3`"}
{$ergebniss};
{$Product_mainimage};
{$Product_desc|regex_replace:"/[;]/":""|strip_tags|strip|trim|truncate:900:"..."} Gr.{$Feed.grange|regex_replace:"/[;]/":"|"};
{$Feed.name};
{$Product_id_cat|escape};
{$Feed.ordernr|trim|regex_replace:"/[ ]/":""};
0;
Y;
{/strip}
{/if}


Ich habe eine IF Abfrage bei einem anderen Feed hinzugefügt.
$output = $smarty->fetch('string:'.$arrFeed->body);
Ich frage mit if (strlen($output) > 10) fwrite($datei_handle,$output."\n");
ab ob etwas in $output steht und schreibe.

Wenn jetzt IF $Feed.rang eq '1' nicht wahr ist
wird trotzdem ein zeilenumbruch geschrieben.

Ich hatte (strlen($output) > 10) schon auf 20 - warum wird geschrieben?

Danke
Christian
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sun Oct 27, 2013 3:33 pm    Post subject: Reply with quote

Smarty Tags "essen" keine Zeilenumbrüche. Also der Zeilenumbruch hintern dem {if...} bleibt erhalten.

Code:
{strip}{if $Feed.rang eq '1'} 
{$Product_deeplink};
{$Product_title|regex_replace:"/[;]/":""|strip_tags|strip|truncate:80:"...":true} {$Feed.ordernr|trim|regex_replace:"/[ ]/":""};
{$Feed.price};
{assign var="ergebniss" value="Schuhe>`$Feed.categorytxt1`>`$Feed.categorytxt2`>`$Feed.categorytxt3`"}
{$ergebniss};
{$Product_mainimage};
{$Product_desc|regex_replace:"/[;]/":""|strip_tags|strip|trim|truncate:900:"..."} Gr.{$Feed.grange|regex_replace:"/[;]/":"|"};
{$Feed.name};
{$Product_id_cat|escape};
{$Feed.ordernr|trim|regex_replace:"/[ ]/":""};
0;
Y;
{/if}{/strip}
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