Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> [smarty] get, include
krystian1991x
post
Post #1





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----


jak mam wstawić zmienną zamiast nazwy pliku ?
  1. {include_php file=zmienna.php}


dodam że tak nie działa
  1. {include_php file="$zmienna.php"}

  1. {include_php file=$zmienna.php}

  1. {include_php file="$zmienna".php}


help !

Ten post edytował krystian1991x 15.10.2010, 12:37:50
Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Mi bez problemu działa ta metoda:
{include_php file=$zmienna.php}
Jeśli Tobie nie działa, to może w $zmienna masz coś innego niż myślisz lub może w ogóle nic nie masz smile.gif
A może scieżki masz złe. Sprawdź

Kod
To jest zmienna: {$zmienna}
{include_php file=$zmienna.php}


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

"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
krystian1991x
post
Post #3





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----


ta zmienna jest przekazywana jako get z pliku tpl do php przetwarzana na normalną zmienną i tam przekazywana do tpl z tym że jak ustawie te zmienną po za funkcją include to wtedy śmiga i pokazuje jest zawartość czyli news i tym podobne

w taki sposób mam podstrony wczytywane
  1. {if $modul == ""}
  2.  
  3. {include_php file="news.php"}
  4.  
  5. {/if}
  6.  
  7. {if $modul != ""}
  8. {include_php file="{$modul}.php"}
  9. {/if}


Zauważyłem że gdy nie ma podanej zmiennej get czyli jest pusta to nie wczytuje mi nic nawet news.php ...
w dodatku gdy już dopisze ręcznie ?id=news to wczytuje owszem ale i tak jak chce zmienić na inną podstronę to zostaje cały czas news.php ...

.
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #4





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Widzę, że nie jesteś uważnym słuchaczem.
Moja odpowiedź w twoim poście rozwiązuje twój problem.

Zamykasz zmienną w ``.
  1. {include file=`$site`.tpl}


Ten post edytował rocktech.pl 15.10.2010, 12:52:17


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
krystian1991x
post
Post #5





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----




Fatal error: Uncaught exception 'Exception' with message 'Syntax Error in template "./templates/index.tpl" on line 36 "{include_php file=`$site`.php} " - Unexpected "`", expected one of: "{" , "$" , "identifier" , LDELIF , LDELFOR , LDELFOREACH , "closing tag" , INTEGER , "+" , "-" , "(" , "(!,not)" , TYPECAST , HEX , "." , SINGLEQUOTESTRING , "#" , "[" , """' in /home/edesing/public_html/libs/sysplugins/smarty_internal_templatecompilerbase.php:403 Stack trace: #0 /home/edesing/public_html/libs/sysplugins/smarty_internal_templateparser.php(2669): Smarty_Internal_TemplateCompilerBase->trigger_template_error() #1 /home/edesing/public_html/libs/sysplugins/smarty_internal_templateparser.php(2734): Smarty_Internal_Templateparser->yy_syntax_error(75, '`') #2 /home/edesing/public_html/libs/sysplugins/smarty_internal_smartytemplatecompiler.php(49): Smarty_Internal_Templateparser->doParse(75, '`') #3 /home/edesing/public_html/libs/sysplugins/smarty_internal_templatecompilerbase.php(82): Smarty_Internal_SmartyTemplateCompiler->do in /home/edesing/public_html/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 403


widzisz żeby działało ?!

  1. {$smarty.get.id}
  2.  
  3. {if $smarty.get.id !=""}
  4. {include_php file="`$smarty.get.id`.php"}
  5. {/if}


ok zrobiłem to aktualnie tak i niby działa ale zawartość na dole nie ulega zmianie tylko za pierwszym razem ładuje mi np jak wczytam news.php to mi wyswietla juz caly czas to i nie moge zmienić na żadną inną podstronę za to cały czas ulega zmianie luźno wrzucona zmienna na nazwy podstron ...
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #6





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Wedle tego powinno zadziałać.

Coś ci się źle parsuje.
Spróbuj tak ale zakładam, że wynik będzie ten sam.
  1. {if $modul != ""}
  2. {assign var="plik" value=`$modul`.php}
  3. {include_php file=$plik}
  4. {/if}


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
krystian1991x
post
Post #7





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----


to prowadzi mnie do punktu wyjścia a pisałem wyżej że już to naprawiłem i jest innej natury problem


to jest poważny problem ;[

zaczyna mnie to irytować już powoli ... ;/
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #8





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Pokaż cały kod w obecnej postaci. .php i .tpl. Zerkniemy, może problem leży w pliku .php.

Generalnie poniższy kod nie powinien być zmartwieniem warstw widoku jaką są smarty. nie myślałeś o przeniesieniu tego do pliku *.php.

  1. {if $modul != ""}
  2. {include_php file="{$modul}.php"}
  3. {/if}


Poproszę kod.


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
krystian1991x
post
Post #9





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----


index.php
  1. <?php
  2. require('libs/Smarty.class.php');
  3. require('cfg.php');
  4.  
  5. $smarty = new Smarty;
  6.  
  7. $_GET['id'];
  8.  
  9.  
  10. $smarty->assign("site", $_GET['id']);
  11.  
  12. $smarty->display('index.tpl');
  13.  
  14. ?>
  15.  

index.tpl
  1. <!doctype html public "-//w3c//dtd html 4.01 transitional//en">
  2. <head>
  3. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  4. <meta name="generator" content="pspad editor, www.pspad.com">
  5. <link rel="stylesheet" type="text/css" href="templates/style.css" />
  6. </head>
  7. <body>
  8. <div id="site">
  9. <div id="head">
  10. <div id="login">
  11. {include_php file="login.php"}
  12. </div>
  13. </div>
  14. <div id="menu">
  15. <div style="padding-left: 35px;">
  16. <table cellspacing="0" cellpadding="0"><tr>
  17. <td><a href="index.php?id=news"><img border="0" src="templates/images/aktualnosci.jpg"></a></td><td><img border="0" src="templates/images/kreska.jpg"></td>
  18. <td><a href="index.php?id=comments"><img border="0" src="templates/images/multimedia.jpg"></a></td><td><img border="0" src="templates/images/kreska.jpg"></td>
  19. <td><a href="#"><img border="0" src="templates/images/download.jpg"></a></td><td><img border="0" src="templates/images/kreska.jpg"></td>
  20. <td><a href="#"><img border="0" src="templates/images/artykuly.jpg"></a></td><td><img border="0" src="templates/images/kreska.jpg"></td>
  21. <td><a href="#"><img border="0" src="templates/images/forum.jpg"></a></td><td><img border="0" src="templates/images/kreska.jpg"></td>
  22. <td><a href="#"><img border="0" src="templates/images/faq.jpg"></a></td><td><img border="0" src="templates/images/kreska.jpg"></td>
  23. <td><a href="#"><img border="0" src="templates/images/kontakt.jpg"></a></td>
  24. </tr></table>
  25. </div>
  26. </div>
  27. <div>
  28.  
  29. {if $site ==""}
  30. {$site}
  31. zmienna site jest pusta
  32. {include_php file="news.php"}
  33. {/if}
  34. {if $site !=""}
  35. {$site}
  36. zmienna site posiada wartosc
  37. {include_php file="`$site`.php"}
  38. {/if}
  39.  
  40. </div>
  41. </div>
  42. </body>
  43. </html>
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #10





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Ok pokaż jeszcze co się dzieje w pliku np. news.php, że chcesz go załączyć do szablonu.


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
krystian1991x
post
Post #11





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----


  1. <?php
  2.  
  3. require('cfg.php');
  4.  
  5. $smarty = new Smarty;
  6.  
  7. $result = mysql_query("SELECT id, title, author, text, img, date, commnets FROM news ORDER BY id ASC")
  8. or die("Niepoprawne zapytanie MySQL");
  9.  
  10.  
  11. while ($news = mysql_fetch_array($result))
  12. {
  13. $tablica[] = $news;
  14.  
  15. }
  16.  
  17. $smarty->assign('result',$tablica);
  18.  
  19.  
  20.  
  21. $smarty->display('news.tpl');
  22. ?>
  23.  


dodam że jak includuje konkretny plik to wtedy działa czyli np zamiast zmiennej w include jest news.php
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #12





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


No i wyszło szydło z worka. To co się dzieje w pliku news.php jest absolutnie bez sensu!

index.php - tu tworzysz obiekt smarty RAZ w pliku news.php masz do niego dostęp.

  1. <?php
  2. require('libs/Smarty.class.php');
  3. require('cfg.php');
  4.  
  5. $smarty = new Smarty;
  6.  
  7. switch($_GET['id']) {
  8. case 'news':
  9. require('news.php');
  10. break;
  11. }
  12.  
  13. $smarty->assign("site", $_GET['id']);
  14. $smarty->display('index.tpl');
  15.  
  16. ?>


news.php - tu nie potrzebujesz jeszcze raz tworzyć obiektu smarty, ustawiasz zmienne dla szablonu news.tpl
  1. <?php
  2. $result = mysql_query("SELECT id, title, author, text, img, date, commnets FROM news ORDER BY id ASC")
  3. or die("Niepoprawne zapytanie MySQL");
  4.  
  5.  
  6. while ($news = mysql_fetch_array($result))
  7. {
  8. $tablica[] = $news;
  9.  
  10. }
  11.  
  12. $smarty->assign('result',$tablica);
  13.  
  14.  
  15. ?>


w index.tpl includujesz plik tpl a nie plik .php . Smarty ma array result który wypełniłeś danymi w news.php i pliku news.tpl robisz np {foreach} czy {section}
  1. {if $site ==""}
  2. {$site}
  3. zmienna site jest pusta
  4. {include file="news.tpl"}
  5. {/if}
  6. {if $site !=""}
  7. {$site}
  8. zmienna site posiada wartosc
  9. {include file="`$site`.tpl"}
  10. {/if}


Teraz spróbuj przerobić swój kod, może uda ci się przy okazji rozwiązać to bardziej elegancko.




--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
krystian1991x
post
Post #13





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----


zrobiłem tak jak napisałeś ale cóż nie działa sciana.gif
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #14





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


1. Jakie błędy wywala?
2. index.php?id=news - teraz zadziała tylko w tym przypadku
3. Masz plik news.tpl, jeżeli tak co w nim masz ?


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
krystian1991x
post
Post #15





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----


nie wywala błędów a dubluje mi news.php czyli wyświetla mi 2 razy jeden raz na górze strony a drugi raz tam gdzie pierwotnie powinno być :/ Teraz staram się jeszcze zrobić tak abym nie musiał każdej podstrony dopisywać bo to bez sensu jak ich będzie kilkadziesiąt ...

ok mam już wszystko zrobione brakuje mi odpowiedzi na pytanie dlaczego mi dubluje to co includuje ?! ;/
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #16





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


To do wywalenia z index.php zakładając, że kod login.php podobny do news.php.

  1. {include_php file="login.php"}


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
krystian1991x
post
Post #17





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----


nie login.php jest osobno ładowany i nie jest pod stroną a częścią konstrukcji szablonu
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #18





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Możesz pokazać kod pliku login.php ?


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
krystian1991x
post
Post #19





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----


  1. <?php
  2.  
  3. require('cfg.php');
  4.  
  5. $smarty = new Smarty;
  6.  
  7. if (isset($_POST['login']) && isset($_POST['password'])) {
  8.  
  9. $login = $_POST['login'];
  10.  
  11. $password = $_POST['password'];
  12.  
  13. $password = md5($password);
  14.  
  15. $sql = "SELECT id, login, password FROM users WHERE login='".$login."' and password='".$password."'";
  16.  
  17. $result = mysql_query($sql) or die (mysql_error());
  18.  
  19. if (mysql_num_rows($result) == 1) {
  20.  
  21. $login_status= "SELECT id, login, password, level, points
  22. FROM users
  23. WHERE login='".$_POST['login']."'";
  24.  
  25. $status = mysql_query($login_status) or die (mysql_error());
  26. $status_user = mysql_fetch_array($status);
  27.  
  28. $_SESSION['zalogowany'] = $status_user['id'];
  29. $_SESSION['login2'] = $status_user['login'];
  30. $_SESSION['points'] = $status_user['points'];
  31.  
  32. } else {
  33.  
  34. $blad = 1;
  35.  
  36. $smarty->assign('blad', $blad);
  37.  
  38.  
  39. }
  40.  
  41. }
  42.  
  43. if ($_GET['logout'] == "log")
  44. {
  45. $sdestroy = session_destroy();
  46.  
  47. $smarty->assign('destroy', $sdestroy);
  48. }
  49. $smarty->assign('points', $_SESSION['points']);
  50. $smarty->assign('id', $_SESSION['zalogowany']);
  51. $smarty->assign('login2', $_SESSION['login2']);
  52. $smarty->display('login.tpl');
  53. return $return;
  54.  
  55.  
  56.  
  57.  
  58. ?>
  59.  


jak usunę $smarty = new Smarty; to mi wywali błąd więc tam musi zapewne pozostać
  1. Fatal error: Call to a member function assign() on a non-object in /home/edesing/public_html/login.php on line 50
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #20





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Nie wiem dlaczego się upierasz żeby całą logikę aplikacji opierać o Smarty. W pliku login.php tworzyłeś nowy obiekt smarty nadpisując ten z index.php!!!

Wywalasz to include login.php z indexu zastępujesz {include file=login.tpl}.
Dajesz include('login.php'); w index.php w linni 7.

A plik login php ma wyglądać tak.
  1. <?php
  2.  
  3. if (isset($_POST['login']) && isset($_POST['password'])) {
  4.  
  5. $login = $_POST['login'];
  6.  
  7. $password = $_POST['password'];
  8.  
  9. $password = md5($password);
  10.  
  11. $sql = "SELECT id, login, password FROM users WHERE login='".$login."' and password='".$password."'";
  12.  
  13. $result = mysql_query($sql) or die (mysql_error());
  14.  
  15. if (mysql_num_rows($result) == 1) {
  16.  
  17. $login_status= "SELECT id, login, password, level, points
  18. FROM users
  19. WHERE login='".$_POST['login']."'";
  20.  
  21. $status = mysql_query($login_status) or die (mysql_error());
  22. $status_user = mysql_fetch_array($status);
  23.  
  24. $_SESSION['zalogowany'] = $status_user['id'];
  25. $_SESSION['login2'] = $status_user['login'];
  26. $_SESSION['points'] = $status_user['points'];
  27.  
  28. } else {
  29.  
  30. $blad = 1;
  31.  
  32. $smarty->assign('blad', $blad);
  33.  
  34.  
  35. }
  36.  
  37. }
  38.  
  39. if ($_GET['logout'] == "log")
  40. {
  41. $sdestroy = session_destroy();
  42.  
  43. $smarty->assign('destroy', $sdestroy);
  44. }
  45. $smarty->assign('points', $_SESSION['points']);
  46. $smarty->assign('id', $_SESSION['zalogowany']);
  47. $smarty->assign('login2', $_SESSION['login2']);
  48. //szablon już wyświetlasz w pliku index.php tu potrzebujesz tylko zmiennych do szablonu login.tpl
  49. //$smarty->display('login.tpl');
  50. //return $return;
  51.  
  52.  
  53.  
  54.  
  55. ?>


Ten post edytował rocktech.pl 15.10.2010, 17:51:20


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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 Aktualny czas: 21.08.2025 - 05:36