Prvi problem mi je što želim da uradim preko Smarty da mi se čitaju neki podatci iz baze i da se autoamtski pravi lista isčitanih npr poruka sa checkboxovima koji kad kliknem da se izbrišu.Evo koda koji sam uradio.
Ovaj kod koji ću da postavim mi izlista checkboxova onoliko koliko ima i redova u tabeli ali nece da mi izlista npr imena kao output, već u svakom redu piše array
Php
Code:
<?php
// These are the smarty files
require 'Smarty.class.php';
require 'baza.php';
$smarty = new Smarty;
$sql=mysql_query("SELECT * FROM `knjige`");
$value=array();
// For each result that we got from the Database
while ($line = mysql_fetch_assoc($sql))
{
$value[] = $line;
}
// Assign this array to smarty...
$smarty->assign('podaci',$value);
// Display the news page through the news template
$smarty->display('ch.tpl');
?>
<?php
// These are the smarty files
require 'Smarty.class.php';
require 'baza.php';
$smarty = new Smarty;
$sql=mysql_query("SELECT * FROM `knjige`");
$value=array();
// For each result that we got from the Database
while ($line = mysql_fetch_assoc($sql))
{
$value[] = $line;
}
// Assign this array to smarty...
$smarty->assign('podaci',$value);
// Display the news page through the news template
$smarty->display('ch.tpl');
?>
Evo tpl koda.
Code:
<html>
<head>
</head>
<body>
{html_checkboxes name='id' values=$podaci output=$podaci.naziv separator='<br />'}
</body>
</html>
<html>
<head>
</head>
<body>
{html_checkboxes name='id' values=$podaci output=$podaci.naziv separator='<br />'}
</body>
</html>
Slijedeće šti mi treba je da mi neko prokomentariše kod koji sam uradio i da li je ispravan način.Uradio sam npr ovaj prethodni primjer u php ali sam ga obradio u Smarty.Zanima me da li sam ispravno ovo uradio.
Php
Code:
<?php
require 'Smarty.class.php';
require 'baza.php';
$smarty = new Smarty;
$uzmi=$_POST['checkbox'];
foreach($uzmi as $nesto)
{
$upit=mysql_query("DELETE FROM $tabela WHERE id=$nesto");
}
if($upit){
$value='true';
}
else
{
$value='ne';
}
// Assign this array to smarty...
$smarty->assign(upit,$value);
// Display the news page through the news template
$smarty->display('izbrisi.tpl');
?>
<?php
require 'Smarty.class.php';
require 'baza.php';
$smarty = new Smarty;
$uzmi=$_POST['checkbox'];
foreach($uzmi as $nesto)
{
$upit=mysql_query("DELETE FROM $tabela WHERE id=$nesto");
}
if($upit){
$value='true';
}
else
{
$value='ne';
}
// Assign this array to smarty...
$smarty->assign(upit,$value);
// Display the news page through the news template
$smarty->display('izbrisi.tpl');
?>
Tpl
Code:
<html>
<head>
</head>
<body>
{if $upit='true'}
Uspjesno izbrisano hahdqodqohdoq
{else}
Nemoze
{/if}
</body>
</html>
<html>
<head>
</head>
<body>
{if $upit='true'}
Uspjesno izbrisano hahdqodqohdoq
{else}
Nemoze
{/if}
</body>
</html>
Samo da napomenem da mi ovaj kod funkcioniše i da radi onako kako sam ga zamislio.
I 3će pitanje je zašto bi koristio npr ovu mogućnost Smarty-a
Code:
{$smarty.post.page}
{$smarty.post.page}
kada mogu uraditi to POST metodom u Php i samo poslati ispis u templejt. Malo me ovo zbunilo jer ako smarty sluzi za razdvajanje logike od prezentacije, zašto nudi ovu opciju ako bi to mogao uraditi i u Php.
I želio bih da se svima zahvalim na komentarima i savjetima, početnik sam u Php tako da molim malo strpljenja.