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


Joined: 12 Sep 2012
Posts: 3

PostPosted: Wed Sep 12, 2012 4:04 pm    Post subject: Array Problem Reply with quote

Hallo zusammen!

Ich habe ein kleines Problem mit SMARTY und einem Array.
Ich benutze für meine Webseite ein Modulsystem, mit dem ich verschiedenen Benutzern verschiedene Module freischalten lassen kann. Jetzt habe ich das Problem, dass ich mitten auf einer Seite ein Feld ausblenden muss. Dazu muss ich in dem Array nach der modul_id suchen um zu schauen, welche Rechte der User hat. Wie ist das möglich?

{if $user_module.modul_id == 3 AND $user_module.rw > 1}
=> Funktioniert nicht.

Ich denke, man muss diese ID angeben, aber kann man das nicht irgendwie umgehen, da die ID sich ja schließlich ändern kann.

0 => Array (5)

Code:
  0 => Array (5)
    id => "6"
    user_id => "1"
    gruppen_id => "1"
    modul_id => "1"
    rw => "2"
  1 => Array (5)
    id => "7"
    user_id => "1"
    gruppen_id => "1"
    modul_id => "2"
    rw => "2"
  2 => Array (5)
    id => "11"
    user_id => "1"
    gruppen_id => "1"
    modul_id => "3"
    rw => "2"
  3 => Array (5)
    id => "14"
    user_id => "1"
    gruppen_id => "1"
    modul_id => "4"
    rw => "2"
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Wed Sep 12, 2012 5:48 pm    Post subject: Reply with quote

Hi, könntest du vllt mal genau erklären was du machen willst?



Quote:
Ich denke, man muss diese ID angeben, aber kann man das nicht irgendwie umgehen, da die ID sich ja schließlich ändern kann.


Meinst du mit "ID angeben" in deinem Fall die 3? Wenn ja, dann kann man das schon umgehen und zwar mit einer Variable die dann ja "dynamisch" sein kann. Je nach dem wie dein System aufgebaut ist und es funktioniert.

Quote:
{if $user_module.modul_id == 3 AND $user_module.rw > 1}
=> Funktioniert nicht.


Was genau funktioniert nicht? Ist denn $user_module der Eintrag aus dem Array oder ist user_module das array an sich?

Wenn es das array an sich ist, dann wird es so auch nicht funktionieren!
Back to top
View user's profile Send private message Visit poster's website
ich007
Smarty n00b


Joined: 12 Sep 2012
Posts: 3

PostPosted: Wed Sep 12, 2012 6:13 pm    Post subject: Reply with quote

Hi, schonmal danke für die Hilfe!

Also, was ich machen will, ist testen, ob der Array Wert "rw" bei der "modul_id" größer als 1 ist.
$user_module ist dabei das komplette Array, wie unten angegeben, aus dem SMARTY Debug-Fenster kopiert.

Die ID die ich meinte ist die "Eintragsnummer" im Array, die hatte ich unten extra rot-gefärbt.

Ich habe mich jetzt nochmal näher damit befasst und eigentlich würde es reichen, wenn ich diese "Eintragsnummer" umgehen könnte.

Quote:
Eintragsnummer??
Wenn ich in php ein Array definiere, dann bekommt jeder Eintrag eine Nummer. Diese Nummer meine ich.
Code:
<?php
$obst = Array("Apfel", "Birne");
?>

0 = Apfel
1 = Birne


Gruß
Jan
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Wed Sep 12, 2012 6:39 pm    Post subject: Reply with quote

Diese Nummer die du meinst nennt sich "Index" sie fängt im Normalfall bei 0 an.

Du hast aber ein assoziatives/mehrdimensionales array Vorliegen. Das würde in etwa so aussehen:

Code:

$arr = array("foo" => "bar", 12 => true);


So um nun auf einen bestimmten Index zuzugreifen macht man es so (Smarty):

Code:
{$meinArray.0}


In deinem obigen Beispiel würde es z. B. "Apfel" ausgeben.

Wenn du aber im Index 0 ein weiteres Array vorliegen hast, kannst du z. B. so auf den den Index zugreifen (Smarty):

Code:
{$meinArray.0.ID}


Schau dir also am betsen das hier an: http://www.smarty.net/docsv2/de/language.function.foreach.tpl

Punkt 7.6 (es ist zwar Smarty 2, aber es funktioniert auch mit Smarty 3)
Back to top
View user's profile Send private message Visit poster's website
ich007
Smarty n00b


Joined: 12 Sep 2012
Posts: 3

PostPosted: Wed Sep 12, 2012 7:23 pm    Post subject: Reply with quote

Index war das Wort, dass ich gesucht habe.

Ok, dann muss ich also jeden Eintrag durchgehen und auslesen und dann schauen. Kann man den Index irgendwie überspringen?


Gruß
Jan
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Thu Sep 13, 2012 5:41 am    Post subject: Reply with quote

Ja das geht und zwar mit continue
Back to top
View user's profile Send private message Visit poster's website
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