2004-04-13 08:46:28 +00:00
|
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
|
|
|
|
<!-- $Revision$ -->
|
2004-10-02 12:49:29 +00:00
|
|
|
|
<!-- EN-Revision: 1.2 Maintainer: thomasgm Status: ready -->
|
2004-04-13 08:46:28 +00:00
|
|
|
|
<sect1 id="language.function.foreach">
|
|
|
|
|
|
<title>foreach,foreachelse</title>
|
|
|
|
|
|
<informaltable frame="all">
|
|
|
|
|
|
<tgroup cols="5">
|
|
|
|
|
|
<colspec colname="param" align="center" />
|
|
|
|
|
|
<colspec colname="type" align="center" />
|
|
|
|
|
|
<colspec colname="required" align="center" />
|
|
|
|
|
|
<colspec colname="default" align="center" />
|
|
|
|
|
|
<colspec colname="desc" />
|
|
|
|
|
|
<thead>
|
|
|
|
|
|
<row>
|
|
|
|
|
|
<entry>Nome do Atributo</entry>
|
|
|
|
|
|
<entry>Tipo</entry>
|
2004-09-22 14:57:20 +00:00
|
|
|
|
<entry>Obrigat<EFBFBD>rio</entry>
|
2004-04-13 08:46:28 +00:00
|
|
|
|
<entry>Padr<EFBFBD>o</entry>
|
|
|
|
|
|
<entry>Descri<EFBFBD><EFBFBD>o</entry>
|
|
|
|
|
|
</row>
|
|
|
|
|
|
</thead>
|
|
|
|
|
|
<tbody>
|
|
|
|
|
|
<row>
|
|
|
|
|
|
<entry>from</entry>
|
|
|
|
|
|
<entry>string</entry>
|
|
|
|
|
|
<entry>Sim</entry>
|
2004-09-22 14:57:20 +00:00
|
|
|
|
<entry><emphasis>n/d</emphasis></entry>
|
2004-04-13 08:46:28 +00:00
|
|
|
|
<entry>O nome da matriz que voc<6F> estar<61> pegando os elementos</entry>
|
|
|
|
|
|
</row>
|
|
|
|
|
|
<row>
|
|
|
|
|
|
<entry>item</entry>
|
|
|
|
|
|
<entry>string</entry>
|
|
|
|
|
|
<entry>Yes</entry>
|
2004-09-22 14:57:20 +00:00
|
|
|
|
<entry><emphasis>n/d</emphasis></entry>
|
2004-04-13 08:46:28 +00:00
|
|
|
|
<entry>O nome da vari<72>vel
|
|
|
|
|
|
que <20> o elemento atual</entry>
|
|
|
|
|
|
</row>
|
|
|
|
|
|
<row>
|
|
|
|
|
|
<entry>key</entry>
|
|
|
|
|
|
<entry>string</entry>
|
|
|
|
|
|
<entry>N<EFBFBD>o</entry>
|
2004-09-22 14:57:20 +00:00
|
|
|
|
<entry><emphasis>n/d</emphasis></entry>
|
2004-04-13 08:46:28 +00:00
|
|
|
|
<entry>O nome da vari<72>vel que <20> a chave atual</entry>
|
|
|
|
|
|
</row>
|
|
|
|
|
|
<row>
|
|
|
|
|
|
<entry>name</entry>
|
|
|
|
|
|
<entry>string</entry>
|
|
|
|
|
|
<entry>N<EFBFBD>o</entry>
|
2004-09-22 14:57:20 +00:00
|
|
|
|
<entry><emphasis>n/d</emphasis></entry>
|
2004-04-13 08:46:28 +00:00
|
|
|
|
<entry>O nome do loop foreach para acessar as
|
|
|
|
|
|
propriedades foreach</entry>
|
|
|
|
|
|
</row>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</tgroup>
|
|
|
|
|
|
</informaltable>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Loops <emphasis>foreach</emphasis> s<>o uma alternativa para loops
|
|
|
|
|
|
<emphasis>section</emphasis>. <emphasis>foreach</emphasis> <20> usado
|
2004-09-22 14:57:20 +00:00
|
|
|
|
para pegar cada elemento de uma matriz associativa simples.
|
2004-04-13 08:46:28 +00:00
|
|
|
|
A sintaxe para <emphasis>foreach</emphasis> <20> muito mais simples do que
|
|
|
|
|
|
<emphasis>section</emphasis>, mas tem a desvantagem de poder ser usada
|
|
|
|
|
|
apenas para uma <20>nica matriz. Tags <emphasis>foreach</emphasis> devem ter
|
|
|
|
|
|
seu par <emphasis>/foreach</emphasis>. Os par<61>metros requeridos s<>o
|
|
|
|
|
|
<emphasis>from</emphasis> e <emphasis>item</emphasis>. O nome do loop
|
|
|
|
|
|
foreach pode ser qualquer coisa que voc<6F> queira, feito de letras, n<>meros
|
|
|
|
|
|
e sublinhados. Loops <emphasis>foreach</emphasis>
|
|
|
|
|
|
podem ser aninhados, e o nome dos loops aninhados devem ser diferentes
|
|
|
|
|
|
um dos outros. A vari<72>vel <emphasis>from</emphasis> (normalmente uma
|
|
|
|
|
|
matriz de valores) determina o n<>mero de vezes do loop
|
|
|
|
|
|
<emphasis>foreach</emphasis>.
|
|
|
|
|
|
<emphasis>foreachelse</emphasis> <20> executado quando n<>o houverem mais valores
|
|
|
|
|
|
na vari<72>vel <emphasis>from</emphasis>.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<example>
|
|
|
|
|
|
<title>foreach</title>
|
|
|
|
|
|
<programlisting>
|
2004-09-22 14:57:20 +00:00
|
|
|
|
<![CDATA[
|
2004-04-13 08:46:28 +00:00
|
|
|
|
{* este exemplo ir<69> mostrar todos os valores da matriz $custid *}
|
|
|
|
|
|
{foreach from=$custid item=curr_id}
|
2004-09-22 14:57:20 +00:00
|
|
|
|
id: {$curr_id}<br>
|
2004-04-13 08:46:28 +00:00
|
|
|
|
{/foreach}
|
2004-09-22 14:57:20 +00:00
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>MOSTRA:</para>
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
id: 1000<br>
|
|
|
|
|
|
id: 1001<br>
|
|
|
|
|
|
id: 1002<br>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
2004-04-13 08:46:28 +00:00
|
|
|
|
</example>
|
|
|
|
|
|
|
|
|
|
|
|
<example>
|
|
|
|
|
|
<title>foreach key</title>
|
|
|
|
|
|
<programlisting>
|
2004-09-22 14:57:20 +00:00
|
|
|
|
<![CDATA[
|
2004-04-13 08:46:28 +00:00
|
|
|
|
{* A key cont<6E>m a chave para cada valor do loop
|
|
|
|
|
|
|
2004-09-22 14:57:20 +00:00
|
|
|
|
A defini<6E><69>o se parece com isso:
|
2004-04-13 08:46:28 +00:00
|
|
|
|
|
2004-09-22 14:57:20 +00:00
|
|
|
|
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
|
|
|
|
|
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
2004-04-13 08:46:28 +00:00
|
|
|
|
|
|
|
|
|
|
*}
|
|
|
|
|
|
|
|
|
|
|
|
{foreach name=outer item=contact from=$contacts}
|
|
|
|
|
|
{foreach key=key item=item from=$contact}
|
2004-09-22 14:57:20 +00:00
|
|
|
|
{$key}: {$item}<br>
|
2004-04-13 08:46:28 +00:00
|
|
|
|
{/foreach}
|
|
|
|
|
|
{/foreach}
|
2004-09-22 14:57:20 +00:00
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>MOSTRA:</para>
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
phone: 1<br>
|
|
|
|
|
|
fax: 2<br>
|
|
|
|
|
|
cell: 3<br>
|
|
|
|
|
|
phone: 555-4444<br>
|
|
|
|
|
|
fax: 555-3333<br>
|
|
|
|
|
|
cell: 760-1234<br>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
2004-04-13 08:46:28 +00:00
|
|
|
|
</example>
|
|
|
|
|
|
|
|
|
|
|
|
<para>
|
2004-09-22 14:57:20 +00:00
|
|
|
|
Loop foreach tamb<6D>m tem as suas pr<70>prias vari<72>veis para manipilar as propriedades
|
2004-04-13 08:46:28 +00:00
|
|
|
|
foreach. Estas s<>o indicadas assim: {$smarty.foreach.foreachname.varname} com
|
|
|
|
|
|
foreachname sendo o nome especificado no atributo
|
|
|
|
|
|
<emphasis>name</emphasis> do foreach.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<sect2 id="foreach.property.iteration">
|
|
|
|
|
|
<title>iteration</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
iteration <20> usado para mostrar a intera<72><61>o atual do loop.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Iteration sempre come<6D>a em 1 e
|
|
|
|
|
|
<09> incrementado um a um em cada intera<72><61>o.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
|
|
|
|
<sect2 id="foreach.property.first">
|
|
|
|
|
|
<title>first</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
<emphasis>first</emphasis> <20> definido como true se a intera<72><61>o atual
|
|
|
|
|
|
do foreach for a primeira.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
|
|
|
|
<sect2 id="foreach.property.last">
|
|
|
|
|
|
<title>last</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
<emphasis>last</emphasis> <20> definido como true se a intera<72><61>o atual
|
|
|
|
|
|
do foreach for a <20>ltima.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
|
|
|
|
<sect2 id="foreach.property.show">
|
|
|
|
|
|
<title>show</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
<emphasis>show</emphasis> <20> usado como par<61>metro para o foreach.
|
|
|
|
|
|
<emphasis>show</emphasis> <20> um valor booleano, true ou false. Se
|
|
|
|
|
|
false, o foreach n<>o ser<65> mostrado. Se tiver um foreachelse
|
|
|
|
|
|
presente, este ser<65> alternativamente mostrado.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
<sect2 id="foreach.property.total">
|
|
|
|
|
|
<title>total</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
<emphasis>total</emphasis> <20> usado para mostrar o n<>mero de intera<72><61>es do
|
|
|
|
|
|
foreach. Isto pode ser usado dentro ou depois do foreach.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</sect1>
|
|
|
|
|
|
<!-- 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
|
|
|
|
|
|
-->
|