Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [HTML][PHP] Jak to rozgryść
Gibcio2008
post 28.06.2023, 09:38:08
Post #1





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 26.10.2008

Ostrzeżenie: (0%)
-----


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. }
Go to the top of the page
+Quote Post
nospor
post 28.06.2023, 09:59:37
Post #2





Grupa: Moderatorzy
Postów: 36 469
Pomógł: 6300
Dołączył: 27.12.2004




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?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
Gibcio2008
post 28.06.2023, 10:16:26
Post #3





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 26.10.2008

Ostrzeżenie: (0%)
-----


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'));


Ten post edytował Gibcio2008 28.06.2023, 10:20:39
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 30.05.2024 - 06:28