Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [HTML][PHP] Jak to rozgryść
Forum PHP.pl > Forum > Przedszkole
Gibcio2008
Witam !
Mam problem, zagwostkę czemu zmiany nie ulega to co jest pogrubione lecz tylko główna część {% loop:user|users %}

Tak są przechowywane dane
  1. $this->variable = array('users' => array('users_login' => 'aaa', 'users_login' => 'bbb');
  2. $this->variable = array('friends' => array('users_login' => 'bbb', 'users_friend' => 'aaa');


Szablon HTML
  1. <div class="users_item_list">
  2. {% loop:user|users %}
  3.  
  4. <div>{user|users_login}</div>
  5. <div></div>
  6. <div>
  7. {% loop:friend|friends %}
  8. {friend|users_friend}
  9. {% endif %}
  10. </div>
  11.  
  12. {% endloop %}
  13. </div>






Do $this->template jest wczytany szablon
  1. if(preg_match_all("/{% loop:(.*)[\|](.*) %}\s(.+)\s{% endloop %}/Us", $this->template, $matches)) {
  2. for($i=0; $i < count($matches[0]); $i++) {
  3.  
  4. $loopVariable = $matches[1][$i];
  5. $arrayVariable = $matches[2][$i];
  6. $loopContent = $matches[3][$i];
  7. $result = "";
  8.  
  9.  
  10. if(isset($this->variable[$arrayVariable]) && is_array($this->variable[$arrayVariable])) {
  11. foreach($this->variable[$arrayVariable] as $name) {
  12. $this->loops[$loopVariable] = $name;
  13. $result .= $this->replaceVariable($loopContent);
  14. }
  15. }
  16.  
  17. $this->template = str_replace($matches[0][$i], $result, $this->template);
  18. }
  19. }



  1. private function replaceVariable($loopContent) {
  2. if(preg_match_all("/{(.*?)[\|](.*?)}/s", $loopContent, $matches)) {
  3. for($i=0; $i < count($matches[0]); $i++) {
  4. if(isset($this->loops[$matches[1][$i]]) && is_array($this->loops[$matches[1][$i]])) {
  5. foreach($this->loops[$matches[1][$i]] as $name => $value) {
  6. $loopContent = str_replace("{".$matches[1][$i]."|".$name."}", $value, $loopContent);
  7. }
  8. }
  9. return $loopContent;
  10. }
  11. }
  12. }
nospor
nie bardzo kumam co napisales, ale tutaj
$this->variable = array('users' => array('users_login' => 'aaa', 'users_login' => 'bbb');
$this->variable = array('friends' => array('users_login' => 'bbb', 'users_friend' => 'aaa');

przeciez w drugiej linicje nadpisujesz pierwsza. Wiec moze to ma wplyw na twoj problem?
Gibcio2008
Sorki mój błąd, print_r pokazuje taką formę

  1. $this->variable['users'] = array('0' => array('users_login' => 'aaa'), '1' => array('users_login' => 'bbb'));
  2. $this->variable['friends'] = array('0' => array('users_login' => 'bbb', 'users_friend' => 'aaa'));
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.