Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> smarty i stripslashes
maciu
post 28.02.2006, 10:37:58
Post #1





Grupa: Zarejestrowani
Postów: 238
Pomógł: 1
Dołączył: 27.08.2003

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


Mam tablicę, której zawartością są dane pobrane z bazy danych.

Teraz chcę wyświetlić dane z tej tablicy w smarty.
  1. <?php
  2.  
  3. function wyswietl() {
  4. $sql = 'SELECT * FROM tabela ';
  5. $result = $this->db->query($sql);
  6.  
  7. $data = array();
  8. while($row = $this->db->fetch($result,$type)) {
  9.  $this->data[] = $row;
  10. }
  11. return $this->data;
  12. }
  13.  
  14. $array = wyswietl();
  15. $template->assign('dane', $array);
  16. $template->display('tresc.tpl');
  17.  
  18. ?>


Kod
{section name=i loop=$dane}
    {$smarty.section.i.iteration}
    {$dane[i].imie}
    {$dane[i].nazwisko}
    {$dane[i].glosy}
{/section}

problem polega na tym, że jeśli dane w bazie zawierają cudzysłowa, apostrofy to wyświetla je ze slashem. Dlatego trzeba zastosować funkcję stripslashes().
Ale gdzie mam to zrobić?

Nie chciałbym, aby stripslashes był już zastosowany w tablicy, jak to jest pokazane w manualu

Smarty jakoś sobię z tym radzi?
Go to the top of the page
+Quote Post
mike
post 28.02.2006, 11:05:53
Post #2





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

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


Nawet jak Smarty czegoś nie ma to łatwo sobie to dopisać :-)

Wkej ten plik do folderu plugins:

modifier.stripslashes.php
  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8. /**
  9.  * Smarty fck modifier plugin
  10.  *
  11.  * Type:  modifier<br>
  12.  * Name:  stripslashes<br>
  13.  * Purpose: stripslashes
  14.  * @param string
  15.  * @return string
  16.  */
  17.  
  18. function smarty_modifier_stripslashes( $string )
  19. {
  20. return stripslashes( $string );
  21. }
  22.  
  23. ?>


Kod
{$variable|stripslashes}
Go to the top of the page
+Quote Post
son
post 28.02.2006, 18:36:04
Post #3





Grupa: Zarejestrowani
Postów: 210
Pomógł: 0
Dołączył: 31.01.2004
Skąd: Kraków

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


A nie łatwiej {$var|sslash}?


--------------------
Warsztat: Apache 1.3.36 | MySQL 4.1.19 | php 5.1.4 | OS Linux SUSE 10.3 x86_64 | Kernel 2.6.22.12-0.1 | Opera 9.5 | Kate
Na warsztacie: Ekartki
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 26.04.2024 - 10:30