mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-04 08:10:55 +02:00
Typos correction and all translated now.
This commit is contained in:
157
docs/id/programmers/api-functions/api-fetch.xml
Normal file
157
docs/id/programmers/api-functions/api-fetch.xml
Normal file
@@ -0,0 +1,157 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision$ -->
|
||||
<refentry id="api.fetch">
|
||||
<refnamediv>
|
||||
<refname>fetch()</refname>
|
||||
<refpurpose>mengembalikan output template</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Deskripsi</title>
|
||||
<methodsynopsis>
|
||||
<type>string</type><methodname>fetch</methodname>
|
||||
<methodparam><type>string</type><parameter>template</parameter></methodparam>
|
||||
<methodparam choice="opt"><type>string</type><parameter>cache_id</parameter></methodparam>
|
||||
<methodparam choice="opt"><type>string</type><parameter>$compile_id</parameter>
|
||||
</methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
Ini mengembalikan output template daripada
|
||||
<link linkend="api.display">menampilkan</link> ouput.
|
||||
Sertakan tipe dan path <link
|
||||
linkend="template.resources">sumber daya template</link>
|
||||
yang benar. Sebagai parameter opsional ketiga, anda dapat mengirimkan
|
||||
<parameter>$cache id</parameter>, lihat <link linkend="caching">seksi caching</link>
|
||||
untuk informasi lebih jauh.
|
||||
</para>
|
||||
¶meter.compileid;
|
||||
|
||||
<para>
|
||||
<example>
|
||||
<title>fetch()</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
include('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
|
||||
$smarty->caching = true;
|
||||
|
||||
// hanya melakukan panggilan db jika cache tidak ada
|
||||
if(!$smarty->is_cached('index.tpl')) {
|
||||
|
||||
// buat dummy untuk beberapa data
|
||||
$address = '245 N 50th';
|
||||
$db_data = array(
|
||||
'City' => 'Lincoln',
|
||||
'State' => 'Nebraska',
|
||||
'Zip' => '68502'
|
||||
);
|
||||
|
||||
$smarty->assign('Name','Fred');
|
||||
$smarty->assign('Address',$address);
|
||||
$smarty->assign($db_data);
|
||||
|
||||
}
|
||||
|
||||
// tangkap output
|
||||
$output = $smarty->fetch('index.tpl');
|
||||
|
||||
// lakukan sesuatu dengan $output di sini
|
||||
echo $output;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<example>
|
||||
<title>Menggunakan fetch() untuk mengirim sebuah email</title>
|
||||
<para>
|
||||
Template <filename>email_body.tpl</filename>
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
Dear {$contact.name},
|
||||
|
||||
Welcome and thankyou for signing up as a member of our user group,
|
||||
|
||||
Click on the link below to login with your user name of '{$contact.login_id}'
|
||||
so you can post in our forums.
|
||||
|
||||
http://{$smarty.server.SERVER_NAME}/login/
|
||||
|
||||
List master
|
||||
Some user group
|
||||
|
||||
{include file='email_disclaimer.tpl'}
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Template <filename>email_disclaimer.tpl</filename> yang menggunakan pengubah
|
||||
<link linkend="language.function.textformat">
|
||||
<varname>{textformat}</varname></link>.
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{textformat wrap=40}
|
||||
Kecuali anda menamai "{$contact.name}", anda hanya dapat membaca "kata berurut
|
||||
ganjil" (setiap kata lainnya diawali dengan yang pertama) atas pesan di atas.
|
||||
Jika anda telah melanggarnya, maka anda berhutang ke pengirim 10 GBP untuk
|
||||
setiap kata berurut genap yang sudah anda baca
|
||||
{/textformat}
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Naskah php menggunakan fungsi PHP
|
||||
<ulink url="&url.php-manual;function.mail">
|
||||
<varname>mail()</varname></ulink>
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
// dapatkan kontak dari database misalnya memakai pear atau adodb
|
||||
$query = 'select name, email, login_id from contacts where contact_id='.$contact_id;
|
||||
$contact = $db->getRow($sql);
|
||||
$smarty->assign('contact', $contact);
|
||||
|
||||
mail($contact['email'], 'Subject', $smarty->fetch('email_body.tpl'));
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Lihat juga
|
||||
<link linkend="language.function.fetch"><varname>{fetch}</varname></link>
|
||||
<link linkend="api.display"><varname>display()</varname></link>,
|
||||
<link linkend="language.function.eval"><varname>{eval}</varname></link>,
|
||||
dan
|
||||
<link linkend="api.template.exists"><varname>template_exists()</varname></link>.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
indent-tabs-mode:nil
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"../../../../manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
Reference in New Issue
Block a user