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

Array Problem

 
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
sadistic
Smarty n00b


Joined: 22 Sep 2004
Posts: 4

PostPosted: Wed Sep 22, 2004 4:14 pm    Post subject: Array Problem Reply with quote

Wie spreche ich arrays in smarty an wenn der array key dynamisch sein soll?

$groups = array(1 => Mitglieder,
2 => Privat,
3 => usw..);


ich versuche folgendes

{$groups[$resume[result].group]}

{$group[1]} = Mitglieder (das geht)
$result[result].group kommt aus einer section schleife und gibt int zurück

nur beides kombiniert geht nicht kann mir da bitte wer helfen?
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Thu Sep 23, 2004 6:32 am    Post subject: Reply with quote

Assoziative Arrays musst du anders ansprechen!

@see http://smarty.php.net/manual/en/language.variables.assoc.arrays.php
Back to top
View user's profile Send private message
sadistic
Smarty n00b


Joined: 22 Sep 2004
Posts: 4

PostPosted: Thu Sep 23, 2004 8:33 am    Post subject: Reply with quote

ich hab aber nicht ein array sondern 2

und das ergebnis des ersten arrays ($resume[result].group)
ist der schlüssel für das zweite array ($groups[])

und da steht leider kein beispiel auf der seite wie man ein array behandelt das ein zweites als key braucht

bitte kann mir wer ein beispiel geben?

thx im vorraus
Back to top
View user's profile Send private message
sadistic
Smarty n00b


Joined: 22 Sep 2004
Posts: 4

PostPosted: Thu Sep 23, 2004 8:49 am    Post subject: Reply with quote

Hier mal der Code:

php-file

<?
include_once('../includes/ob_start.php');
require_once('../config/config.inc.php');
require_once('../classes/class_newsletter.php');
new newsletter(array('session', 'smarty_loader', 'resume', 'groups'), $class, true, true);

$smarty =& $class['smarty_loader']->smarty;

$smarty->assign('logo', HTML_LOGO);
$smarty->assign('appname', APPNAME);
$smarty->assign('groups', $class['resume']->getGroups());
$smarty->assign('resume', $class['resume']->getResumeData());
$smarty->display('admin_newsletter_resume.html');
include_once('../includes/ob_end.php');
?>

die zugewiesenen Arrays:

$groups = Array
(
[2] => Geschäftlich
[1] => Mitglieder
[3] => Privat
);

$resume = Array
(
[0] => Array
(
[id] => 12
[max_value] => 500
[value] => 267
[date] => 00.00.0000
[time] => 00:00:00
[prozent] => 53.40
[type] => text
[group] => 1
[subject] => kein subject
[message] => testmessage
)
);
und der auszug aus dem tpl file



{section name=result loop=$resume}
{if $resume[result].group eq ""}
Alle
{elseif $resume[result].group == "0"}
Keine Gruppe
{else}
// SO und hier besteht mein Problem
{$groups.resume.result.group} -> geht nicht
{$groups.$resume.result.group} -> geht nicht
{$groups[$resume[result].group]} -> geht nicht
{/if}
{/section}


wäre sehr nett wenn mir wer die lösung für dieses problem sagen könnte, dies ist leider mein erstes projekt mit smarty, und ne richtige beschreibung für dieses problem gibts nicht
Back to top
View user's profile Send private message
sadistic
Smarty n00b


Joined: 22 Sep 2004
Posts: 4

PostPosted: Thu Sep 23, 2004 10:05 am    Post subject: Reply with quote

Code:

{if $resume[result].group eq ""}
  Alle
{elseif $resume[result].group == "0"}
  Keine Gruppe
{else}
  {foreach name=gr key=key item=value from=$groups}
      {if $key eq $resume[result].group}
          {$value}
      {/if}
  {/foreach}
{/if}


Ok ich habe das jetzt so gelöst, obwohl ich diese Methode ziemlich merkwürdig finde Laughing

Naja falls es doch eine andere Lösung geben sollte, wäre es nett wenn es mir wer posten würde.

danke
Back to top
View user's profile Send private message
coach
Smarty Regular


Joined: 03 Jun 2004
Posts: 65

PostPosted: Thu Sep 23, 2004 4:18 pm    Post subject: Reply with quote

Hi,

ich glaube, ich hatte das gleiche Problem mal mit einem
Code:
{assign}
gelöst.

Coach[/quote]
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