![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
![]() Grupa: Zarejestrowani Postów: 217 Pomógł: 0 Dołączył: 5.10.2003 Skąd: Londyn / UK Ostrzeżenie: (0%) ![]() ![]() |
[php:1:e0b2753167]<?php
require_once "Smarty.class.php"; $smarty = new Smarty(); $smarty->template_dir = '/usr/local/apache/htdocs/templates'; $smarty->compile_dir = '/usr/local/apache/htdocs/templates_c'; $smarty->config_dir = '/usr/local/apache/htdocs/configs'; $smarty->cache_dir = '/usr/local/apache/htdocs/cache'; $smarty->assign('site_name' , 'United Gaming'); mysql_connect('localhost' , 'root' , '123qwe'); mysql_select_db("test"); $id=$_GET['id']; if (!$id) { echo "Podaj paramentr"; } else { $sql = "SELECT * FROM ug_users WHERE ug_id=$id"; $result=mysql_query($sql); $row = mysql_fetch_array($result); } $smarty->assign('Profile' , array('id' => $row["ug_id"], 'nick' => $row["ug_nick"], 'irc' => $row["ug_irc"], 'gg' => $row["ug_gg"], 'www' => $row["ug_www"], 'lastlogin' => $row["ug_lastlogin"], 'status' => $row["ug_status"], 'comm_n' => $row["ug_comm_n"], 'news_n' => $row["ug_news_n"], 'regdate' => $row["ug_regdate"], 'logins_n' => $row["ug_logins_n"], 'opis' => $row["ug_opis"], 'lastlogin' => $row["ug_lastlogin"], 'email' => $row["ug_email"])); function edit_user() { $sql = "UPDATE ug_users SET ug_nick=$ug_nick WHERE ug_id=$id"; $result=mysql_query($sql); } $smarty->register_function("edit_us" , "edit_user"); $smarty->display('edit.tpl'); ?>[/php:1:e0b2753167] i kod pliku edit.tpl [xml:1:e0b2753167]<html xmlns=http://www.w3.org/1999/xhtml" xml; lang="en" lan="en"> <head> <title>{$site_name} - Profil uzytkownika {$Profile.nick} [{$Profile.id}]</title> </head><hr> <body><h2>Edytowanie uzytkownika {$Profile.nick}</h2><hr><BR> <form method="POST" action="{edit_us}"> Nick: <input type=text name"nick" value="{$Profile.nick}"> <BR> E-mail: <input type=text name"nick" value="{$Profile.email}"> <BR> Gadu-Gadu: <input type=text name"nick" value="{$Profile.gg}"> <BR> IRC: <input type=text name"nick" value="{$Profile.irc}"> <BR> Strona WWW: <input type=text name"nick" value="{$Profile.www}"> <BR><BR> Status: {$Profile.status}<BR><BR> Data rejestracji: {$Profile.regdate} <BR> Ilosc logowan: {$Profile.logins_n} <BR> Ostatnie Logowanie: {$Profile.lastlogin}<BR> <BR>Newsy: {$Profile.news_n} <BR> Komentarze: {$Profile.comm_n} <BR><BR>Opis:<BR> <textarea name"opis" cols=60 rows=10>{$Profile.opis}</textarea><BR><BR> <input type="submit" name=wyslij "value="Zapisz"> <input type="reset" name=wyslij "value="Resetuj"> </form> </body> </html> [/xml:1:e0b2753167] Teraz mam 2 pytania. Jak wywolac z pliku edit.tpl funkcje {edit_us} z parametrem id ktory mam albo w linku albo w sesji oraz jak wszystkie pola dodac do bazy. W smartach jestem zielony wiec prosze lopatologicznie. |
|
|
![]()
Post
#2
|
|
![]() Grupa: Zarząd Postów: 2 277 Pomógł: 6 Dołączył: 27.12.2002 Skąd: Wołów/Wrocław ![]() |
!@#@!# - manual - juz ci to tłumaczyłem na ircu. przykłąd tam podany jest PIĘKNY.
Cytat register_function
void register_function(string name, string impl); Use this to dynamically register template function plugins. Pass in the template function name, followed by the php function name that implements it. 101 Chapter 13. Methods Example 13-22. register_function $smarty->register_function("date_now", "print_current_date"); function print_current_date ($params) { extract($params); if(empty($format)) $format="%b %e, %Y"; echo strftime($format,time()); } // now you can use this in Smarty to print the current date: {date_now} // or, {date_now format="%Y/%m/%d"} to format it. Czy to nie wystarczy by zobaczyć, że do odwołania sie do parametrów potrzebna jest tablica (tu $params) do której trafiają wszytie parametry podane w tpl, (tu $format ) -------------------- "Niezależnie od tego, jakie masz osiągnięcia, ktoś Ci pomaga..."
|
|
|
![]()
Post
#3
|
|
![]() Grupa: Przyjaciele php.pl Postów: 554 Pomógł: 0 Dołączył: 4.04.2002 Skąd: Tychy Ostrzeżenie: (0%) ![]() ![]() |
Kod {insert script="./templates/scripts/insert_photo.php" name="photo" dir="wina" foto=$output.wynik[i].foto }
to jest przyklad jak wywoluje funkcjie wstawiajaca funkcje wstawiajaca zdjecia ![]() teraz tak: script - nie musze tlumaczyc name- nazwa funkcji w skrypcie musi chba byc "smarty_insert_photo" dir, foto - sa zapisane w tablicy ktora jest parametrem funkcji ad 2 jeslichesz cos z sesji to np {$smarty.session.twoja_zmienna} czyli np Kod {insert script="./templates/scripts/twoj_plik.php" name="naz_funkcji" var1=$smarty.session.twoja_zmienna }
idt. -------------------- "Real children don't go hoppity-skip unless they are on drugs."
|
|
|
![]() ![]() |
![]() |
Aktualny czas: 21.08.2025 - 13:39 |