mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-29 19:31:36 +01:00
141 lines
5.3 KiB
XML
141 lines
5.3 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<sect1 id="language.function.include.php">
|
|
<title>include_php</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 Attributo</entry>
|
|
<entry>Tipo</entry>
|
|
<entry>Obbligatorio</entry>
|
|
<entry>Default</entry>
|
|
<entry>Descrizione</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>file</entry>
|
|
<entry>stringa</entry>
|
|
<entry>sì</entry>
|
|
<entry><emphasis>nessuno</emphasis></entry>
|
|
<entry>Nome del file php da includere</entry>
|
|
</row>
|
|
<row>
|
|
<entry>once</entry>
|
|
<entry>booleano</entry>
|
|
<entry>no</entry>
|
|
<entry><emphasis>true</emphasis></entry>
|
|
<entry>Se includere o no il file php più di una volta nel
|
|
caso venga richiesto più volte</entry>
|
|
</row>
|
|
<row>
|
|
<entry>assign</entry>
|
|
<entry>stringa</entry>
|
|
<entry>no</entry>
|
|
<entry><emphasis>nessuno</emphasis></entry>
|
|
<entry>Nome della variabile cui sarà assegnato l'output
|
|
di include_php</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
<note>
|
|
<title>Nota Tecnica</title>
|
|
<para>
|
|
include_php è deprecato da Smarty, in quanto potete ottenere la
|
|
stessa funzionalità attraverso una funzione utente.
|
|
L'unica ragione per usare include_php è se avete una reale
|
|
necessità di tenere fuori la funzione php dalla directory dei plugin
|
|
o dal vostro codice applicativo. Vedere l'<link
|
|
linkend="tips.componentized.templates">esempio di template a
|
|
componenti</link> per i dettagli.
|
|
</para>
|
|
</note>
|
|
<para>
|
|
i tag include_php sono usati per includere uno script php nel
|
|
template. Se la security è abilitata, lo script php si deve
|
|
trovare nel percorso di $trusted_dir. Il tag include_php deve
|
|
avere l'attributo "file", che contiene il percorso al file da
|
|
includere, che può essere assoluto relativo alla directory $trusted_dir.
|
|
</para>
|
|
<para>
|
|
include_php è un ottimo modo per gestire template a componenti, e
|
|
tiene il codice PHP separato dai file dei template. Diciamo che abbiamo
|
|
un template che mostra la navigazione del nostro sito, che viene
|
|
prelevata dinamicamente da un database. Possiamo tenere la logica PHP
|
|
che ottiene il contenuto del database in una directory separata, ed
|
|
includerla in cima al template. Ora possiamo includere questo
|
|
template ovunque senza preoccuparci che l'applicazione abbia
|
|
preventivamente caricato i dati del database.
|
|
</para>
|
|
<para>
|
|
Per default, i file php sono inclusi una sola volta, anche se richiesti
|
|
più volte nel template. Potete specificare che devono essere inclusi
|
|
ogni volta con l'attributo <emphasis>once</emphasis>. Se impostate
|
|
once a false, lo script verrà incluso tutte le volte che viene
|
|
richiesto nel template.
|
|
</para>
|
|
<para>
|
|
Opzionalmente potete passare l'attributo <emphasis>assign</emphasis>,
|
|
che specifica un nome di variabile cui sarà assegnato l'output di
|
|
<emphasis>include_php</emphasis>, invece di essere visualizzato.
|
|
</para>
|
|
<para>
|
|
L'oggetto smarty è disponibile come $this all'interno dello script
|
|
PHP che viene incluso.
|
|
</para>
|
|
<example>
|
|
<title>funzione include_php</title>
|
|
<programlisting>
|
|
load_nav.php
|
|
-------------
|
|
|
|
<?php
|
|
|
|
// carichiamo le variabili da un db mysql e le assegnamo al template
|
|
require_once("MySQL.class.php");
|
|
$sql = new MySQL;
|
|
$sql->query("select * from site_nav_sections order by name",SQL_ALL);
|
|
$this->assign('sections',$sql->record);
|
|
|
|
?>
|
|
|
|
|
|
index.tpl
|
|
---------
|
|
|
|
{* percorso assoluto, o relativo a $trusted_dir *}
|
|
{include_php file="/path/to/load_nav.php"}
|
|
|
|
{foreach item="curr_section" from=$sections}
|
|
<a href="{$curr_section.url}">{$curr_section.name}</a><br>
|
|
{/foreach}</programlisting>
|
|
</example>
|
|
</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
|
|
-->
|