|
Kuliah TKI : Smarty Introduction |
|
|
|
|
Written by Administrator
|
|
Wednesday, 18 June 2008 |
Materi terakhir Kuliah topik khusus Internet adalah tentang PHP template engine dan PHP framework. Untuk PHP template Engine, diperkenalkan tentang smarty, sedang untuk PHP framework diperkenalkan tentang Symfony. Berikut adalah apa yang dibahas saat kuliah pengenalan untuk smarty
MATERI - copykan folder smarty, bisa direname agar sesuai isi website. - buat file untuk tampilan seperti berikut : (bentuk design di dreamweavernya) hello {$a} simpan di folder templates, misal belajar1.htm
- buat file php untuk bussiness prosesnya <? require_once('libs/smarty.class.php'); $sm=new smarty(); $sm->template_dir='templates'; $sm->compile_dir='templates_c'; $sm->cache_dir='cache'; $sm->config_dir='configs'; $nama="yudi"; $sm->assign("a",$nama); $sm->display("belajar1.htm"); ?> simpan di lokasi smarty, misal belajar1.php
- browse localhost/smarty/belajar1.php -> seharusnya keluar Hello Yudi
- Looping. tambahkan di belajar1.htm <ol> {foreach from=$buahbuahan item=buah} <li>{$buah}</li> {/foreach} </ol> di belajar1.php ditambahi di sebelum $sm->display.. $fruits=array("papaya","mango","banana", "guava"); $sm->assign("buahbuahan",$fruits); array 2 dimensi: tambahkan di belajar1.htm {foreach from=$products item=p} {$p.id}-{$p.nama}-{$p.harga}<br> {/foreach}
tambahkan di belajar1.php $p1=array("id"=>"P01","nama"=>"pensil","harga"=>2000); $p2=array("id"=>"P02","nama"=>"spidol","harga"=>4000); $p3=array("id"=>"P03","nama"=>"bolpoin","harga"=>6000); $produk=array($p1,$p2,$p3); $sm->assign("products",$produk); LATIHAN Tampilkan data dari Postgres. misal data mahasiswa. ditampilkan dalam bentuk tabel. hint : dapat menggunakan pg_fetch_all untuk mengambil seluruh isi hasil query kedalam array 2 dimensi. contoh : $result=pg_query("select * from mhs"); $mhs=pg_fetch_all($result);
di belajar1.php ditambahkan :
$con=pg_connect("host=localhost port=5432 dbname=tki_daniel user=postgres password=postgres "); $query="SELECT * FROM mahasiswa"; $hasil=pg_query($con,$query); $rs=pg_fetch_all($hasil); $sm->assign("mhs",$rs);
di belajar1.htm ditambah dengan tabel :
<table width="75%" border="1"> <tr bgcolor="#330099"> <td>NRP </td> <td>NAMA</td> <td>IPK</td> </tr> {foreach from=$mhs item=m} <tr> <td>{$m.nrp}</td> <td>{$m.nama}</td> <td>{$m.ipk}</td> </tr> {/foreach} </table>
IF : misal untuk yang IPK < 2 diwarnai merah, untuk IPK>3.5 diberi keterangan "CUMLAUDE" -> tambahkan di tr misal <tr {if $m.ipk<2} bgcolor="red" {/if} > <td>{$m.nrp}</td> <td>{$m.nama}</td> <td>{$m.ipk} {if $m.ipk>3.5} (CUMLAUDE) {/if} </td> </tr>
|
Kuliah TKI - Blog da...
mm Apparently, 21,000 boots imported by
Clas-class php yang ...
mm Apparently, 21,000 boots imported by
Kuliah TK Internet :...
mm Apparently, 21,000 boots imported by
The Power of GIS - U...
mm Apparently, 21,000 boots imported by
Kuliah TK Internet :...
mm Apparently, 21,000 boots imported by
JPGraph - membuat gr...
timberland - mm Apparently, 21,000 bo...
Kuliah TKI : Ajax - ...
mm Apparently, 21,000 boots imported by
Banner spesial untuk...
mm Apparently, 21,000 boots imported by