mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-02 13:21:36 +01:00
1106 lines
41 KiB
XML
1106 lines
41 KiB
XML
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
|||
|
|
<!-- $Revision$ -->
|
|||
|
|
<chapter id="api.functions">
|
|||
|
|
<title>M<EFBFBD>todos</title>
|
|||
|
|
<sect1 id="api.append">
|
|||
|
|
<title>append</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>append</function></funcdef>
|
|||
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>append</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>varname</parameter></paramdef>
|
|||
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>append</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>varname</parameter></paramdef>
|
|||
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|||
|
|
<paramdef>boolean <parameter>merge</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso <20> usado para adicionar um elemento para um array fixado. Se voc<6F> adicionar
|
|||
|
|
uma string como valor, isso ir<69> converter-se para um valor de array e ent<6E>o adicion<6F>-lo.
|
|||
|
|
Voc<6F> pode explicitamente passar pares nomes/valores, ou arrays associativos
|
|||
|
|
contendo o par nome/valor. Se voc<6F> passar o terceiro par<61>metro opcional para true,
|
|||
|
|
o valor unir-se ao array atual
|
|||
|
|
ao inv<6E>s de ser adicionado.
|
|||
|
|
</para>
|
|||
|
|
<note>
|
|||
|
|
<title>Notas T<>cnicas</title>
|
|||
|
|
<para>
|
|||
|
|
O par<61>metro de uni<6E>o respeita a chave do array, ent<6E>o se voc<6F>
|
|||
|
|
mesclar dois <20>ndices n<>mericos de um array, eles devem sobrescrever-se
|
|||
|
|
um ao outro ou em resultados n<>o sequ<71>ncias de chave. Isso <20> diferente da fun<75><6E>o de PHP array_merge()
|
|||
|
|
que apaga as chaves e as renumera.
|
|||
|
|
</para>
|
|||
|
|
</note>
|
|||
|
|
<example>
|
|||
|
|
<title>append</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// passing name/value pairs
|
|||
|
|
$smarty->append("Name","Fred");
|
|||
|
|
$smarty->append("Address",$address);
|
|||
|
|
|
|||
|
|
// passing an associative array
|
|||
|
|
$smarty->append(array("city" => "Lincoln","state" => "Nebraska"));</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.append.by.ref">
|
|||
|
|
<title>append_by_ref</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>append_by_ref</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>varname</parameter></paramdef>
|
|||
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>append_by_ref</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>varname</parameter></paramdef>
|
|||
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|||
|
|
<paramdef>boolean <parameter>merge</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso <20> usado para adicionar vlaores para o template por refer<65>ncia.
|
|||
|
|
Se voc<6F> adicionar uma vari<72>vel por refer<65>ncia e ent<6E>o alterar este valor
|
|||
|
|
o valor adicionado enxergar<61> a altera<72><61>o tamb<6D>m. Para objetos,
|
|||
|
|
append_by_ref() tamb<6D>m evita uma c<>pia em mem<65>ria do objeto adicionado.
|
|||
|
|
Veja o manual do PHP em referenciando vari<72>veis para uma melhor explana<6E><61>o sobre o assunto.
|
|||
|
|
Se voc<6F> passar o terceiro par<61>metro opcional para true,
|
|||
|
|
o valor ir<69> ser mesclado com o array atual ao inv<6E>s de adicion<6F>-lo.
|
|||
|
|
</para>
|
|||
|
|
<note>
|
|||
|
|
<title>Notas T<>cnicas</title>
|
|||
|
|
<para>
|
|||
|
|
O par<61>metro de uni<6E>o respeita a chave do array, ent<6E>o se voc<6F> mesclar
|
|||
|
|
dois <20>ndices n<>mericos de arrays, eles devem sobrescrever-se um ao outro ou
|
|||
|
|
em resultados n<>o sequ<71>ncias de chave. Isso <20> diferente da fun<75><6E>o de PHP array_merge()
|
|||
|
|
que apaga as chaves num<75>ricas e as renumera.
|
|||
|
|
</para>
|
|||
|
|
</note>
|
|||
|
|
<example>
|
|||
|
|
<title>append_by_ref</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// appending name/value pairs
|
|||
|
|
$smarty->append_by_ref("Name",$myname);
|
|||
|
|
$smarty->append_by_ref("Address",$address);</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.assign">
|
|||
|
|
<title>assign</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>assign</function></funcdef>
|
|||
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>assign</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>varname</parameter></paramdef>
|
|||
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso <20> usado para fixar valores para o template. Voc<6F> pode
|
|||
|
|
explicitamente passar pares de nomes/valores, ou um array associativo
|
|||
|
|
contendo o par de nome/valor.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>assign</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// passing name/value pairs
|
|||
|
|
$smarty->assign("Name","Fred");
|
|||
|
|
$smarty->assign("Address",$address);
|
|||
|
|
|
|||
|
|
// passing an associative array
|
|||
|
|
$smarty->assign(array("city" => "Lincoln","state" => "Nebraska"));</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.assign.by.ref">
|
|||
|
|
<title>assign_by_ref</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>assign_by_ref</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>varname</parameter></paramdef>
|
|||
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso <20> usado para fixar valores para o template por refer<65>ncia ao inv<6E>s de fazer uma c<>pia.
|
|||
|
|
Veja o manual do PHP na parte sobre refer<65>ncia de vari<72>veis para uma explana<6E><61>o mais detalhada.
|
|||
|
|
</para>
|
|||
|
|
<note>
|
|||
|
|
<title>Notas T<>cnicas</title>
|
|||
|
|
<para>
|
|||
|
|
Isso <20> usado para fixar valores para o template por refer<65>ncia.
|
|||
|
|
Se voc<6F> fixar uma vari<72>vel por refer<65>ncia e ent<6E>o alterar o valor dela,
|
|||
|
|
o valor fixado enxergar<61> o valor alterado tamb<6D>m.
|
|||
|
|
Para objetos, assign_by_ref() tamb<6D>m restringe uma c<>pia de objetos fixados
|
|||
|
|
em mem<65>ria.
|
|||
|
|
Veja o manual do php em refereciando vari<72>veis para uma melhor explana<6E><61>o.
|
|||
|
|
</para>
|
|||
|
|
</note>
|
|||
|
|
<example>
|
|||
|
|
<title>assign_by_ref</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// passing name/value pairs
|
|||
|
|
$smarty->assign_by_ref("Name",$myname);
|
|||
|
|
$smarty->assign_by_ref("Address",$address);</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.clear.all.assign">
|
|||
|
|
<title>clear_all_assign</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>clear_all_assign</function></funcdef>
|
|||
|
|
<paramdef><parameter></parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso limpa o valor de todas as vari<72>veis fixadas.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>clear_all_assign</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// clear all assigned variables
|
|||
|
|
$smarty->clear_all_assign();</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.clear.all.cache">
|
|||
|
|
<title>clear_all_cache</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>clear_all_cache</function></funcdef>
|
|||
|
|
<paramdef>int <parameter>expire time</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso limpa completamente o cache de template. Como um par<61>metro
|
|||
|
|
opcional, voc<6F> pode fornecer um ano m<>nimo em segundos
|
|||
|
|
que o arquivo de cache deve ter antes deles serem apagados.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>clear_all_cache</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// clear the entire cache
|
|||
|
|
$smarty->clear_all_cache();</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.clear.assign">
|
|||
|
|
<title>clear_assign</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>clear_assign</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>var</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso limpa o valor de uma vari<72>vel fixada. Isso
|
|||
|
|
pode ser um valor simples, ou um array de valores.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>clear_assign</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// clear a single variable
|
|||
|
|
$smarty->clear_assign("Name");
|
|||
|
|
|
|||
|
|
// clear multiple variables
|
|||
|
|
$smarty->clear_assign(array("Name","Address","Zip"));</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.clear.cache">
|
|||
|
|
<title>clear_cache</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>clear_cache</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>template</parameter></paramdef>
|
|||
|
|
<paramdef>string <parameter><optional>cache id</optional></parameter></paramdef>
|
|||
|
|
<paramdef>string <parameter><optional>compile id</optional></parameter></paramdef>
|
|||
|
|
<paramdef>int <parameter><optional>expire time</optional></parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso limpa o cache de um template espec<65>fico. Se voc<6F> tem
|
|||
|
|
m<>ltiplos caches para este arquivo, voc<6F> limpa o cache
|
|||
|
|
espec<65>fico fornecendo o cache id como o segundo par<61>metro.
|
|||
|
|
Voc<6F> pode tamb<6D>m passar um compile id como um terceiro par<61>metro.
|
|||
|
|
Voc<6F> pode "agrupar" templates juntos e ent<6E>o eles podem ser removidos
|
|||
|
|
como um grupo. Veja o <link linkend="caching">caching section</link> para maiores informa<6D><61>es. Como um quarto
|
|||
|
|
par<61>metro opcional, voc<6F> pode fornecer um ano m<>nimo em segundos
|
|||
|
|
que o arquivo de cache deve
|
|||
|
|
ter antes dele ser apagado.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>clear_cache</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// clear the cache for a template
|
|||
|
|
$smarty->clear_cache("index.tpl");
|
|||
|
|
|
|||
|
|
// clear the cache for a particular cache id in an multiple-cache template
|
|||
|
|
$smarty->clear_cache("index.tpl","CACHEID");</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.clear.compiled.tpl">
|
|||
|
|
<title>clear_compiled_tpl</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>clear_compiled_tpl</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>tpl_file</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso limpa a vers<72>o compilada do recurso de template especificado,
|
|||
|
|
ou todos os arquivos de templates compilados se nenhum for especificado.
|
|||
|
|
Essa fun<75><6E>o <20> para uso avan<61>ado somente, n<>o normalmente necess<73>ria.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>clear_compiled_tpl</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// clear a specific template resource
|
|||
|
|
$smarty->clear_compiled_tpl("index.tpl");
|
|||
|
|
|
|||
|
|
// clear entire compile directory
|
|||
|
|
$smarty->clear_compiled_tpl();</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.clear.config">
|
|||
|
|
<title>clear_config</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>clear_config</function></funcdef>
|
|||
|
|
<paramdef>string <parameter><optional>var</optional></parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso limpa todas as vari<72>veis de configura<72><61>o fixadas. Se um nome de vari<72>vel
|
|||
|
|
<09> fornecido, somente esta vari<72>vel <20> apagada.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>clear_config</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// clear all assigned config variables.
|
|||
|
|
$smarty->clear_config();
|
|||
|
|
|
|||
|
|
// clear one variable
|
|||
|
|
$smarty->clear_config('foobar');</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.config.load">
|
|||
|
|
<title>config_load</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>config_load</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>file</parameter></paramdef>
|
|||
|
|
<paramdef>string <parameter><optional>section</optional></parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso carrega o arquivo de configura<72><61>o de dados e fixa-o para o
|
|||
|
|
template. Isso funciona id<69>ntico a fun<75><6E>o <link
|
|||
|
|
linkend="language.function.config.load">
|
|||
|
|
config_load</link>.
|
|||
|
|
</para>
|
|||
|
|
<note>
|
|||
|
|
<title>Notas T<>cnicas</title>
|
|||
|
|
<para>
|
|||
|
|
<20> partir da Smarty 2.4.0, vari<72>veis de template fixadas s<>o
|
|||
|
|
mantidas atrav<61>s de fetch() e display(). Vari<72>veis de configura<72><61>o carregadas
|
|||
|
|
de config_load() s<>o sempre de escopo global. Arquivos de configura<72><61>o
|
|||
|
|
tamb<6D>m s<>o compilados para execu<63><75>o r<>pida, e repeita o <link
|
|||
|
|
linkend="variable.force.compile">force_compile</link> e <link
|
|||
|
|
linkend="variable.compile.check">compile_check</link> par<61>metros de configura<72><61>o.
|
|||
|
|
</para>
|
|||
|
|
</note>
|
|||
|
|
<example>
|
|||
|
|
<title>config_load</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// load config variables and assign them
|
|||
|
|
$smarty->config_load('my.conf');
|
|||
|
|
|
|||
|
|
// load a section
|
|||
|
|
$smarty->config_load('my.conf','foobar');</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.display">
|
|||
|
|
<title>display</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>display</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>template</parameter></paramdef>
|
|||
|
|
<paramdef>string <parameter><optional>cache_id</optional></parameter></paramdef>
|
|||
|
|
<paramdef>string <parameter><optional>compile_id</optional></parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso mostra o template. Fornecendo um v<>lido <link
|
|||
|
|
linkend="template.resources">template resource</link>
|
|||
|
|
tipo e path. Como um segundo par<61>metro opcional, voc<6F> pode passar
|
|||
|
|
um cache id. Veja o <link linkend="caching">caching
|
|||
|
|
section</link> para maiores informa<6D><61>es.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
Como um terceiro par<61>metro opcional, voc<6F> pode passar um compile id.
|
|||
|
|
Isso est<73> no evento que voc<6F> quer compilar diferentes vers<72>es do
|
|||
|
|
mesmo template, como ter templates compilados separadamente para diferentes linguagens.
|
|||
|
|
Outro uso para compile_id <20> quando voc<6F> usa mais do que um $template_dir
|
|||
|
|
mas somente um $compile_dir. Seta um compile_id em separado para cada $template_dir,
|
|||
|
|
de outra maneira templates com mesmo nome ir<69>o sobrescrever-se um ao outro.
|
|||
|
|
Voc<6F> pode tamb<6D>m setar a vari<72>vel <link
|
|||
|
|
linkend="variable.compile.id">$compile_id</link> ao inv<6E>s de
|
|||
|
|
passar isso para cada chamada
|
|||
|
|
de display().
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>display</title>
|
|||
|
|
<programlisting>
|
|||
|
|
include("Smarty.class.php");
|
|||
|
|
$smarty = new Smarty;
|
|||
|
|
$smarty->caching = true;
|
|||
|
|
|
|||
|
|
// only do db calls if cache doesn't exist
|
|||
|
|
if(!$smarty->is_cached("index.tpl"))
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
// dummy up some 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);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// display the output
|
|||
|
|
$smarty->display("index.tpl");</programlisting>
|
|||
|
|
</example>
|
|||
|
|
<para>
|
|||
|
|
Use a sintaxe para <link
|
|||
|
|
linkend="template.resources">template resources</link> para
|
|||
|
|
mostrar arquivos fora do $template_dir directory.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>Exemplos de recursos da fun<75><6E>o display</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// absolute filepath
|
|||
|
|
$smarty->display("/usr/local/include/templates/header.tpl");
|
|||
|
|
|
|||
|
|
// absolute filepath (same thing)
|
|||
|
|
$smarty->display("file:/usr/local/include/templates/header.tpl");
|
|||
|
|
|
|||
|
|
// windows absolute filepath (MUST use "file:" prefix)
|
|||
|
|
$smarty->display("file:C:/www/pub/templates/header.tpl");
|
|||
|
|
|
|||
|
|
// include from template resource named "db"
|
|||
|
|
$smarty->display("db:header.tpl");</programlisting>
|
|||
|
|
</example>
|
|||
|
|
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.fetch">
|
|||
|
|
<title>fetch</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>string <function>fetch</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>template</parameter></paramdef>
|
|||
|
|
<paramdef>string <parameter><optional>cache_id</optional></parameter></paramdef>
|
|||
|
|
<paramdef>string <parameter><optional>compile_id</optional></parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso retorna a sa<73>da do template ao inv<6E>s de mostr<74>-lo.
|
|||
|
|
Fornecendo um tipo ou path v<>lido <link
|
|||
|
|
linkend="template.resources">template resource</link>.
|
|||
|
|
Como um segundo par<61>metro opcional, voc<6F> pode passar o cache id.
|
|||
|
|
Veja o <link linkend="caching">caching
|
|||
|
|
section</link> para maiores informa<6D><61>es.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
Como um terceiro par<61>metro opcional, voc<6F> pode passar um compile id.
|
|||
|
|
Isso est<73> no evento que voc<6F> quer compilar diferentes vers<72>es do
|
|||
|
|
mesmo template, como ter templates compilados separadamente para
|
|||
|
|
diferentes linguagens. Outro uso para compile_id <20> quando voc<6F>
|
|||
|
|
usa mais do que um $template_dir mas somente um $compile_dir. Seta
|
|||
|
|
um compile_id em separado para cada $template_dir, de outra maneira
|
|||
|
|
templates com mesmo nome ir<69>o sobrescrever-se uns aos outros. Voc<6F>
|
|||
|
|
pode tamb<6D>m setar a vari<72>vel <link
|
|||
|
|
linkend="variable.compile.id">$compile_id</link> ao inv<6E>s
|
|||
|
|
de pass<73>-la para cada chamada de fetch().
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>fetch</title>
|
|||
|
|
<programlisting>
|
|||
|
|
include("Smarty.class.php");
|
|||
|
|
$smarty = new Smarty;
|
|||
|
|
|
|||
|
|
$smarty->caching = true;
|
|||
|
|
|
|||
|
|
// only do db calls if cache doesn't exist
|
|||
|
|
if(!$smarty->is_cached("index.tpl"))
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
// dummy up some 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);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// capture the output
|
|||
|
|
$output = $smarty->fetch("index.tpl");
|
|||
|
|
|
|||
|
|
// do something with $output here
|
|||
|
|
|
|||
|
|
echo $output;</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.get.config.vars">
|
|||
|
|
<title>get_config_vars</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>array <function>get_config_vars</function></funcdef>
|
|||
|
|
<paramdef>string <parameter><optional>varname</optional></parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso retorna o valor da vari<72>vel de configura<72><61>o dada.
|
|||
|
|
Se nenhum par<61>metro <20> dado, um array de todas as vari<72>veis dos arquivos de configura<72><61>es <20> retornado.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>get_config_vars</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// get loaded config template var 'foo'
|
|||
|
|
$foo = $smarty->get_config_vars('foo');
|
|||
|
|
|
|||
|
|
// get all loaded config template vars
|
|||
|
|
$config_vars = $smarty->get_config_vars();
|
|||
|
|
|
|||
|
|
// take a look at them
|
|||
|
|
print_r($config_vars);</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.get.registered.object">
|
|||
|
|
<title>get_registered_object</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>array <function>get_registered_object</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>object_name</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso retorna uma refer<65>ncia para um objeto registrado.
|
|||
|
|
Isso <20> <20>til para dentro de uma fun<75><6E>o customizada quando voc<6F>
|
|||
|
|
precisa acessar diretamente um objeto registrado.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>get_registered_object</title>
|
|||
|
|
<programlisting>
|
|||
|
|
function smarty_block_foo($params, &$smarty) {
|
|||
|
|
if (isset[$params['object']]) {
|
|||
|
|
// get reference to registered object
|
|||
|
|
$obj_ref =& $smarty->&get_registered_object($params['object']);
|
|||
|
|
// use $obj_ref is now a reference to the object
|
|||
|
|
}
|
|||
|
|
}</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.get.template.vars">
|
|||
|
|
<title>get_template_vars</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>array <function>get_template_vars</function></funcdef>
|
|||
|
|
<paramdef>string <parameter><optional>varname</optional></parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso retorna o valor de uma vari<72>vel fixada. Se nenhum par<61>metro
|
|||
|
|
<09> dado, um array de todas as vari<72>vels fixadas <20> retornado.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>get_template_vars</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// get assigned template var 'foo'
|
|||
|
|
$foo = $smarty->get_template_vars('foo');
|
|||
|
|
|
|||
|
|
// get all assigned template vars
|
|||
|
|
$tpl_vars = $smarty->get_template_vars();
|
|||
|
|
|
|||
|
|
// take a look at them
|
|||
|
|
print_r($tpl_vars);</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.is.cached">
|
|||
|
|
<title>is_cached</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>is_cached</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>template</parameter></paramdef>
|
|||
|
|
<paramdef>[string <parameter>cache_id</parameter>]</paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso retorna true se h<> um cache v<>lido para esse template.
|
|||
|
|
Isso somente funciona se <link
|
|||
|
|
linkend="variable.caching">caching</link> est<73> setado para true.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>is_cached</title>
|
|||
|
|
<programlisting>
|
|||
|
|
$smarty->caching = true;
|
|||
|
|
|
|||
|
|
if(!$smarty->is_cached("index.tpl")) {
|
|||
|
|
// do database calls, assign vars here
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$smarty->display("index.tpl");</programlisting>
|
|||
|
|
</example>
|
|||
|
|
<para>
|
|||
|
|
Voc<6F> pode tamb<6D>m passar um cache id como um segundo par<61>metro opcional
|
|||
|
|
no caso voc<6F> quer m<>ltiplos caches para o template dado.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>is_cached with multiple-cache template</title>
|
|||
|
|
<programlisting>
|
|||
|
|
$smarty->caching = true;
|
|||
|
|
|
|||
|
|
if(!$smarty->is_cached("index.tpl","FrontPage")) {
|
|||
|
|
// do database calls, assign vars here
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$smarty->display("index.tpl","FrontPage");</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.load.filter">
|
|||
|
|
<title>load_filter</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>load_filter</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>type</parameter></paramdef>
|
|||
|
|
<paramdef>string <parameter>name</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Essa fun<75><6E>o pode ser usada para carregar um filtro de plugin. O primeiro
|
|||
|
|
argumento especifica o tipo do filtro para carregar e pode ser um
|
|||
|
|
dos seguintes: 'pre', 'post', ou 'output'. O segundo argumento
|
|||
|
|
especifica o nome do filtro de plugin, por exemplo, 'trim'.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>Carregando filtros de plugins</title>
|
|||
|
|
<programlisting>
|
|||
|
|
$smarty->load_filter('pre', 'trim'); // load prefilter named 'trim'
|
|||
|
|
$smarty->load_filter('pre', 'datefooter'); // load another prefilter named 'datefooter'
|
|||
|
|
$smarty->load_filter('output', 'compress'); // load output filter named 'compress'</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.register.block">
|
|||
|
|
<title>register_block</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>register_block</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>name</parameter></paramdef>
|
|||
|
|
<paramdef>mixed <parameter>impl</parameter></paramdef>
|
|||
|
|
<paramdef>bool <parameter>cacheable</parameter></paramdef>
|
|||
|
|
<paramdef>array or null <parameter>cache_attrs</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para registrar dinamicamente blocos de fun<75><6E>es de plugins.
|
|||
|
|
Passe no bloco de nomes de fun<75><6E>o, seguido por uma chamada de fun<75><6E>o PHP
|
|||
|
|
que implemente isso.
|
|||
|
|
</para>
|
|||
|
|
|
|||
|
|
<para>
|
|||
|
|
A chamada de uma fun<75><6E>o-php <parameter>impl</parameter> pode ser (a)
|
|||
|
|
uma string contendo o nome da fun<75><6E>o ou (b) um array no formato
|
|||
|
|
<literal>array(&$object, $method)</literal> com
|
|||
|
|
<literal>&$object</literal> sendo uma refer<65>ncia para um
|
|||
|
|
objeto e <literal>$method</literal> sendo uma string
|
|||
|
|
contendo o nome do m<>todo ou (c) um array no formato
|
|||
|
|
<literal>array(&$class, $method)</literal> com
|
|||
|
|
<literal>$class</literal> sendo um nome de classe e
|
|||
|
|
<literal>$method</literal> sendo um
|
|||
|
|
m<>todo desta classe.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
<parameter>$cacheable</parameter> e <parameter>$cache_attrs</parameter> podem ser omitidos na maior parte dos casos. Veja <link linkend="caching.cacheable">Controlando modos de Sa<53>da de Cache dos Plugins</link> para obter informa<6D><61>es apropriadas.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>register_block</title>
|
|||
|
|
<programlisting>
|
|||
|
|
/* PHP */
|
|||
|
|
$smarty->register_block("translate", "do_translation");
|
|||
|
|
|
|||
|
|
function do_translation ($params, $content, &$smarty, &$repeat) {
|
|||
|
|
if (isset($content)) {
|
|||
|
|
$lang = $params['lang'];
|
|||
|
|
// do some translation with $content
|
|||
|
|
return $translation;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
{* template *}
|
|||
|
|
{translate lang="br"}
|
|||
|
|
Hello, world!
|
|||
|
|
{/translate}</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.register.compiler.function">
|
|||
|
|
<title>register_compiler_function</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>register_compiler_function</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>name</parameter></paramdef>
|
|||
|
|
<paramdef>mixed <parameter>impl</parameter></paramdef>
|
|||
|
|
<paramdef>bool <parameter>cacheable</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para registrar dinamicamente uma fun<75><6E>o de plugin compilador.
|
|||
|
|
Passe no nome da fun<75><6E>o compilador, seguido pela fun<75><6E>o
|
|||
|
|
PHP que implemente isso.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
A chamada para fun<75><6E>o-php <parameter>impl</parameter>
|
|||
|
|
pode ser uma string contendo o nome da fun<75><6E>o ou (b) um array
|
|||
|
|
no formato <literal>array(&$object, $method)</literal> com
|
|||
|
|
<literal>&$object</literal> sendo uma refer<65>ncia para um
|
|||
|
|
objeto e <literal>$method</literal> sendo uma string
|
|||
|
|
contendo o nome do m<>todo ou (c) um array no formato
|
|||
|
|
<literal>array(&$class, $method)</literal> com
|
|||
|
|
<literal>$class</literal> sendo um nome de classe e
|
|||
|
|
<literal>$method</literal> sendo o m<>todo
|
|||
|
|
desta classe.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
<parameter>$cacheable</parameter> pode ser omitido na maioria
|
|||
|
|
dos casos. Veja <link linkend="caching.cacheable">Controlando modos de Sa<53>da de Cache dos Plugins</link>
|
|||
|
|
para obter informa<6D><61>es apropriadas.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.register.function">
|
|||
|
|
<title>register_function</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>register_function</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>name</parameter></paramdef>
|
|||
|
|
<paramdef>mixed <parameter>impl</parameter></paramdef>
|
|||
|
|
<paramdef>bool <parameter>cacheable</parameter></paramdef>
|
|||
|
|
<paramdef>array or null <parameter>cache_attrs</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para registrar fun<75><6E>es de plugins dinamicamente para o template.
|
|||
|
|
Passe no template o nome da fun<75><6E>o,
|
|||
|
|
seguido pelo nome da fun<75><6E>o PHP que implemente isso.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
A chamada para fun<75><6E>o-php <parameter>impl</parameter> pode ser (a)
|
|||
|
|
uma string contendo o nome da fun<75><6E>o ou (b) um array no formato
|
|||
|
|
<literal>array(&$object, $method)</literal> com
|
|||
|
|
<literal>&$object</literal> sendo uma refer<65>ncia para um
|
|||
|
|
objeto e <literal>$method</literal> sendo uma string
|
|||
|
|
contendo o nome do m<>todo ou (c) um array no formato
|
|||
|
|
<literal>array(&$class, $method)</literal> com
|
|||
|
|
<literal>$class</literal> sendo um nome de classe e
|
|||
|
|
<literal>$method</literal> sendo um m<>todo
|
|||
|
|
desta classe.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
<parameter>$cacheable</parameter> e <parameter>$cache_attrs</parameter> podem ser omitidos na maioria dos casos. Veja <link linkend="caching.cacheable">Controlando modos de Sa<53>da Cache dos Plugins</link> para obter informa<6D><61>es apropriadas.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>register_function</title>
|
|||
|
|
<programlisting>
|
|||
|
|
$smarty->register_function("date_now", "print_current_date");
|
|||
|
|
|
|||
|
|
function print_current_date ($params) {
|
|||
|
|
extract($params);
|
|||
|
|
if(empty($format))
|
|||
|
|
$format="%b %e, %Y";
|
|||
|
|
return strftime($format,time());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// agora voc<6F> pode usar isso no Smarty para mostrar a data atual: {date_now}
|
|||
|
|
// ou, {date_now format="%Y/%m/%d"} para formatar isso.</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.register.modifier">
|
|||
|
|
<title>register_modifier</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>register_modifier</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>name</parameter></paramdef>
|
|||
|
|
<paramdef>mixed <parameter>impl</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para modificar dinamicamente plugins registrados.
|
|||
|
|
Passe no template o nome do modificador, seguido da fun<75><6E>o PHP
|
|||
|
|
que implemente isso.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
A chamada da fun<75><6E>o-php <parameter>impl</parameter>
|
|||
|
|
pode ser (a) uma strin contendo o nome da fun<75><6E>o
|
|||
|
|
ou (b) um array no formato
|
|||
|
|
<literal>array(&$object, $method)</literal> com
|
|||
|
|
<literal>&$object</literal> sendo uma refer<65>ncia para um
|
|||
|
|
objeto e <literal>$method</literal> sendo uma string
|
|||
|
|
contendo o nome do m<>todo ou (c) um array no formato
|
|||
|
|
<literal>array(&$class, $method)</literal> com
|
|||
|
|
<literal>$class</literal> sendo um nome de classe e
|
|||
|
|
<literal>$method</literal> sendo um m<>todo desta classe.
|
|||
|
|
</para>
|
|||
|
|
|
|||
|
|
<example>
|
|||
|
|
<title>register_modifier</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// let's map PHP's stripslashes function to a Smarty modifier.
|
|||
|
|
|
|||
|
|
$smarty->register_modifier("sslash","stripslashes");
|
|||
|
|
|
|||
|
|
// now you can use {$var|sslash} to strip slashes from variables</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.register.object">
|
|||
|
|
<title>register_object</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>register_object</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>object_name</parameter></paramdef>
|
|||
|
|
<paramdef>object <parameter>$object</parameter></paramdef>
|
|||
|
|
<paramdef>array <parameter>allowed methods/properties</parameter></paramdef>
|
|||
|
|
<paramdef>boolean <parameter>format</parameter></paramdef>
|
|||
|
|
<paramdef>array <parameter>block methods</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Isso <20> para registrar um objeto para uso no template. Veja a
|
|||
|
|
<link linkend="advanced.features.objects">se<EFBFBD><EFBFBD>o de objetos</link>
|
|||
|
|
do manual para examplos.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.register.outputfilter">
|
|||
|
|
<title>register_outputfilter</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>register_outputfilter</function></funcdef>
|
|||
|
|
<paramdef>mixed <parameter>function</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para registrar dinamicamente filtros de sa<73>da para opera<72><61>es
|
|||
|
|
na sa<73>da do template antes de mostr<74>-lo. Veja
|
|||
|
|
<link linkend="advanced.features.outputfilters">Filtros de Sa<53>da de Templates</link>
|
|||
|
|
para maiores informa<6D><61>es de como configurar uma
|
|||
|
|
fun<75><6E>o de filtro de sa<73>da.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
A chamada da fun<75><6E>o-php <parameter>function</parameter> pode
|
|||
|
|
ser (a) uma string contendo um nome de fun<75><6E>o ou (b) um array no formato
|
|||
|
|
<literal>array(&$object, $method)</literal> com
|
|||
|
|
<literal>&$object</literal> sendo uma refer<65>ncia para um
|
|||
|
|
objeto e <literal>$method</literal> sendo uma string
|
|||
|
|
contendo o nome do m<>todo ou (c) um array no formato
|
|||
|
|
<literal>array(&$class, $method)</literal> com
|
|||
|
|
<literal>$class</literal> sendo um nome de classe e
|
|||
|
|
<literal>$method</literal> sendo um m<>todo
|
|||
|
|
desta classe.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.register.postfilter">
|
|||
|
|
<title>register_postfilter</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>register_postfilter</function></funcdef>
|
|||
|
|
<paramdef>mixed <parameter>function</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para registrar dinamicamente p<>sfiltros para rodar templates
|
|||
|
|
ap<61>s eles terem sido compilados. Veja
|
|||
|
|
<link linkend="advanced.features.postfilters">p<EFBFBD>sfiltros de template</link> para
|
|||
|
|
maiores informa<6D><61>es de como configurar fun<75><6E>es de p<>sfiltragem.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
A chamada da fun<75><6E>o-php <parameter>function</parameter> pode
|
|||
|
|
ser (a) uma string contendo um nome de fun<75><6E>o ou (b) um array no formato
|
|||
|
|
<literal>array(&$object, $method)</literal> com
|
|||
|
|
<literal>&$object</literal> sendo uma refer<65>ncia para um
|
|||
|
|
objeto e <literal>$method</literal> sendo uma string
|
|||
|
|
contendo o nome do m<>todo ou (c) um array no formato
|
|||
|
|
<literal>array(&$class, $method)</literal> com
|
|||
|
|
<literal>$class</literal> sendo um nome de classe e
|
|||
|
|
<literal>$method</literal> sendo um m<>todo
|
|||
|
|
desta classe.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.register.prefilter">
|
|||
|
|
<title>register_prefilter</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>register_prefilter</function></funcdef>
|
|||
|
|
<paramdef>mixed <parameter>function</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para registrar pr<70>filtros dinamicamente para rodar
|
|||
|
|
templates antes deles serem compilados. Veja <link
|
|||
|
|
linkend="advanced.features.prefilters">template prefilters</link> para
|
|||
|
|
maiores informa<6D><61>es de como configurar uma fun<75><6E>o de pr<70>filtragem.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
A chamada da fun<75><6E>o-php <parameter>function</parameter> pode
|
|||
|
|
ser (a) uma string contendo um nome de fun<75><6E>o ou (b) um array no formato
|
|||
|
|
<literal>array(&$object, $method)</literal> com
|
|||
|
|
<literal>&$object</literal> sendo uma refer<65>ncia para um
|
|||
|
|
objeto e <literal>$method</literal> sendo uma string
|
|||
|
|
contendo o nome do m<>todo ou (c) um array no formato
|
|||
|
|
<literal>array(&$class, $method)</literal> com
|
|||
|
|
<literal>$class</literal> sendo um nome de classe e
|
|||
|
|
<literal>$method</literal> sendo um m<>todo
|
|||
|
|
desta classe.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.register.resource">
|
|||
|
|
<title>register_resource</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>register_resource</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>name</parameter></paramdef>
|
|||
|
|
<paramdef>array <parameter>resource_funcs</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para registrar dinamicamente um recurso de plugin com a Smarty.
|
|||
|
|
Passe no nome o recurso e o array de fun<75><6E>es
|
|||
|
|
PHP que implementam isso. Veja
|
|||
|
|
<link linkend="template.resources">template resources</link>
|
|||
|
|
para maiores informa<6D><61>es de como configurar uma fun<75><6E>o para retornar
|
|||
|
|
templates.
|
|||
|
|
</para>
|
|||
|
|
<note>
|
|||
|
|
<title>Notas T<>cnicas</title>
|
|||
|
|
<para>
|
|||
|
|
Um nome de recurso deve ter ao menos dois caracteres de comprimento.
|
|||
|
|
Um caracter do nome de recurso ir<69> ser ignorado e usado como parte do
|
|||
|
|
path do arquivo como, $smarty->display('c:/path/to/index.tpl');
|
|||
|
|
</para>
|
|||
|
|
</note>
|
|||
|
|
<para>
|
|||
|
|
A fun<75><6E>o-php-array <parameter>resource_funcs</parameter>
|
|||
|
|
deve ter 4 ou 5 elementos. Com 4 elementos os elementos s<>o
|
|||
|
|
as functions-callbacks para as respectivas fun<75><6E>es "source",
|
|||
|
|
"timestamp", "secure" e "trusted" de recurso.
|
|||
|
|
Com 5 elementos o primeiro elemento tem que ser um objeto por refer<65>ncia
|
|||
|
|
ou um nome de classe do objeto ou uma classe implementando o recurso e os 4
|
|||
|
|
elementos seguintes tem que ter os nomes de m<>todos
|
|||
|
|
implementando "source", "timestamp",
|
|||
|
|
"secure" e "trusted".
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>register_resource</title>
|
|||
|
|
<programlisting>
|
|||
|
|
$smarty->register_resource("db", array("db_get_template",
|
|||
|
|
"db_get_timestamp",
|
|||
|
|
"db_get_secure",
|
|||
|
|
"db_get_trusted"));</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.trigger.error">
|
|||
|
|
<title>trigger_error</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>trigger_error</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>error_msg</parameter></paramdef>
|
|||
|
|
<paramdef>[int <parameter>level</parameter>]</paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Essa fun<75><6E>o pode ser usada para sa<73>da de uma mensagem de erro usando Smarty.
|
|||
|
|
O par<61>metro <parameter>level</parameter> pode ser um dos valores usados
|
|||
|
|
para a fun<75><6E>o de php trigger_error(), ex.: E_USER_NOTICE,
|
|||
|
|
E_USER_WARNING, etc. Por padr<64>o <20> E_USER_WARNING.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
|
|||
|
|
<sect1 id="api.template.exists">
|
|||
|
|
<title>template_exists</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>bool <function>template_exists</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>template</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Essa fun<75><6E>o checa se o template especificado existe. Isso pode
|
|||
|
|
aceitar um path para o template no filesystem ou um recurso de string
|
|||
|
|
especificando o template.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.unregister.block">
|
|||
|
|
<title>unregister_block</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>unregister_block</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>name</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para desregistrar dinamicamente um bloco de fun<75><6E>es de plugin.
|
|||
|
|
Passe no bloco o nome da fun<75><6E>o.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.unregister.compiler.function">
|
|||
|
|
<title>unregister_compiler_function</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>unregister_compiler_function</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>name</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use essa fun<75><6E>o para desregistrar uma fun<75><6E>o de compilador. Passe
|
|||
|
|
o nome da fun<75><6E>o de compilador.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.unregister.function">
|
|||
|
|
<title>unregister_function</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>unregister_function</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>name</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para desregistrar dinamicamente uma fun<75><6E>o de plugin do template.
|
|||
|
|
Passe no template o nome da fun<75><6E>o.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>unregister_function</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// n<>s n<>o queremos que designers template tenham acesso aos nossos arquivos do sistema
|
|||
|
|
|
|||
|
|
$smarty->unregister_function("fetch");</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.unregister.modifier">
|
|||
|
|
<title>unregister_modifier</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>unregister_modifier</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>name</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para desregistrar dincamimente um modificador de plugin.
|
|||
|
|
Passe no template o nome do modificador.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>unregister_modifier</title>
|
|||
|
|
<programlisting>
|
|||
|
|
// n<>s n<>o queremos que designers de template usem strip tags para os elementos
|
|||
|
|
|
|||
|
|
$smarty->unregister_modifier("strip_tags");</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.unregister.object">
|
|||
|
|
<title>unregister_object</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>unregister_object</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>object_name</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para desregistrar um objeto.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.unregister.outputfilter">
|
|||
|
|
<title>unregister_outputfilter</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>unregister_outputfilter</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>function_name</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para desregistrar dinamicamente um filtro de sa<73>da.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.unregister.postfilter">
|
|||
|
|
<title>unregister_postfilter</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>unregister_postfilter</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>function_name</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para dinamicamente desregistrar um p<>sfiltro.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.unregister.prefilter">
|
|||
|
|
<title>unregister_prefilter</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>unregister_prefilter</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>function_name</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para dinamicamente desregistrar um pr<70>filtro.
|
|||
|
|
</para>
|
|||
|
|
</sect1>
|
|||
|
|
<sect1 id="api.unregister.resource">
|
|||
|
|
<title>unregister_resource</title>
|
|||
|
|
<funcsynopsis>
|
|||
|
|
<funcprototype>
|
|||
|
|
<funcdef>void <function>unregister_resource</function></funcdef>
|
|||
|
|
<paramdef>string <parameter>name</parameter></paramdef>
|
|||
|
|
</funcprototype>
|
|||
|
|
</funcsynopsis>
|
|||
|
|
<para>
|
|||
|
|
Use isso para dinamicamente desregistrar um recurso de plugin.
|
|||
|
|
Passe no par<61>metro nome o nome do recurso.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>unregister_resource</title>
|
|||
|
|
<programlisting>
|
|||
|
|
$smarty->unregister_resource("db");</programlisting>
|
|||
|
|
</example>
|
|||
|
|
</sect1>
|
|||
|
|
</chapter>
|
|||
|
|
<!-- 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
|
|||
|
|
-->
|