Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Czy to jest "w porządku"?
byther
post
Post #1





Grupa: Zarejestrowani
Postów: 40
Pomógł: 0
Dołączył: 15.06.2004
Skąd: Warszawa

Ostrzeżenie: (10%)
X----


Najlepiej podam żywy przykład. Najpierw stwórzmy strukturę...
Kod
#!/bin/bash
mkdir public templates templates_c public/action public/view
chmod 777 templates_c
touch index.php public/action/akcja.php public/view/index.php templates/page.tpl


A zawartość to:

/public/action/akcja.php
  1. <?php
  2. $tpl->assign( 'test', true );
  3. return 'view/index';
  4. ?>


/public/view/index.php
  1. <?php
  2. $template = 'page.tpl';
  3. ?>


/templates/page.tpl
  1. <a href="index.php">Indeks</a> |
  2. <a href="index.php?q=view/index">Indeks 1</a> |
  3. <a href="index.php?q=action/akcja">Akcja</a>
  4. <hr/>
  5. Szablon: OK<br/>
  6. {if $test}
  7. Zmienna: OK<br/>
  8. {/if}


/index.php
  1. <?php
  2. define( 'APPDIR', dirname( __FILE__ ) . '/' );
  3. require_once( 'smarty/Smarty.class.php' );
  4.  
  5. function run( $req )
  6. {
  7. $tpl =& new Smarty;
  8. while( !empty( $req ) && file_exists( APPDIR . 'public/' . $req . '.php' ) )
  9. $req = include( APPDIR . 'public/' . $req . '.php' );
  10. return $tpl->fetch( $template );
  11. }
  12.  
  13. echo run( $_REQUEST['q'] ? $_REQUEST['q'] : 'view/index' );
  14. ?>


Przykład jest banalnie prosty. Chyba jednak nie do końca potrafię zrozumieć jego potencjał (o ile takowy istnieje). Na ile można coś takiego wykorzystać?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 03:52