Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Szablony a'la ZF, Podobne rozwiazanie...
kicaj
post 22.10.2007, 11:22:58
Post #1





Grupa: Zarejestrowani
Postów: 1 640
Pomógł: 28
Dołączył: 13.02.2003
Skąd: Międzyrzecz/Poznań

Ostrzeżenie: (0%)
-----


Jak wykonywane sa szablony w ZendFramework?
Plik szablonu (.phtml):
  1. <html>
  2. <head></head>
  3. <body><?php echo $this -> text; ?></body>
  4. </html>


Plik kontrolera:
  1. <?php
  2. class NazwaController
  3. {
  4. function IndexAction()
  5. {
  6. $this -> view -> text = 'Napis';
  7. }
  8. }
  9. ?>


Jak to sie odbywa, jak w pliku .phtml odbierana jest wartosc 'text'?
Probowalem przegladac Zend_View ale nie moglem dojsc do tego...

Ten post edytował kicaj 25.10.2007, 13:43:23


--------------------
PHP Developer

"Nadmiar wiedzy jest równie szkodliwy jak jej brak" Émile Zola
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
jang
post 25.10.2007, 08:27:03
Post #2





Grupa: Zarejestrowani
Postów: 101
Pomógł: 11
Dołączył: 2.02.2005

Ostrzeżenie: (0%)
-----


Ja mam tak:
index.php :
  1. <?php
  2. $objFront = new CCC_Controller_Front;
  3. $objFront->dispatch();
  4. ?>

FrontController :
  1. <?php
  2. public function dispatch()
  3. {
  4. $this->objRouter = new CCC_Router($this->objInput, $this->objConfig);
  5. CCC::registrySet('router', $this->objRouter);
  6.  
  7. $this->objView = new CCC_View;
  8. CCC::registrySet('view', $this->objView);
  9.  
  10.  
  11. $controller = strtolower($this->objRouter->getController());
  12. $action = strtolower($this->objRouter->getAction());
  13. $this->perform($controller, $action);
  14. }
  15.  
  16. public function perform($controller, $action)
  17. {
  18. $objController = new $controller($this);
  19. $objController->$action();
  20. }
  21. ?>

Kontroller akcji :
  1. <?php
  2. class CCC_Controller_Action
  3. {
  4. function __construct($objFront)
  5. {
  6. $this->objFront = $objFront;
  7. $this->objView = $this->objFront->getView();
  8. $this->objInput = $this->objFront->getInput();
  9.  
  10. $this->init();
  11. }
  12.  
  13.  
  14. public function init()
  15. {
  16. }
  17.  
  18. }
  19. ?>

  1. <?php
  2. class CCC_View
  3. {
  4. /**
  5.  * string $fileName Nazwa pliku PHP który znajduje się w katalogu /app/views
  6.  * bez rozszeżenia (.php)
  7.  * np. $this->view->display('welcome_message');  
  8.  */  
  9. final public function display($fileName = null)
  10. {
  11. if(null === $fileName)
  12. throw new Exception ('Klasa CCC_View::display($fileName = null) : $fileName musi być podane');
  13.  
  14. $filePath = DIR_APP.'views/'.$fileName.'.php';
  15.  
  16. if(!is_readable($filePath))
  17. throw new Exception ('Klasa CCC_View::display($fileName = null) : Nie ma pliku '.$filePath);
  18.  
  19. include ($filePath);
  20. $sContents = ob_get_clean();
  21. return $sContents;
  22. }
  23.  
  24.  
  25. } // end : class CCC_View
  26. ?>

Akcja :
  1. <?php
  2. class IndexController extends CCC_Controller_Action
  3. {
  4.  
  5. public function init()
  6. {
  7. $this->objView->basePath = $this->objInput->getBasePath();
  8. $this->objView->baseUrl = $this->objInput->getBaseUrl();
  9. $this->objView->router = $this->objFront->getRouter();
  10. }
  11.  
  12.  
  13. public function IndexAction()
  14. {
  15. $this->objView->title = 'Welcome';
  16. $site = $this->objView->display('index/index');
  17. echo $site;
  18. }
  19. ?>

tpl :
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  6. <title><?php echo htmlentities($this->title, ENT_QUOTES, 'utf-8'); ?></title>
  7. <link rel="stylesheet" type="text/css" media="screen" 
  8. href="<?php echo $this->basePath ?>/public/styles/skidoo_too.css" />
  9. </head>
  10.  
  11. <body>
  12. <div id="pageWrapper">
  13. <div id="masthead" class="inside">
  14. <img src="<?php echo $this->basePath ?>/public/images/CCC_nag_brown.gif" alt="Cash City">
  15. <hr class="hide">
  16. </div>
  17. <div class="hnav">
  18. <ul>
  19.  <li><a href="<?php echo $this->router->createURL(); ?>">Home</a></li
  20. ><li><a href="<?php echo $this->router->createURL('index', 'server'); ?>">Dane servera</a></li

W tpl nie tak jak Ty napisałeś
  1. Tytul: <b><?php echo $this -> view; ?></b>

tylko :
  1. Tytul: <b><?php echo $this -> title; ?></b>

a tablice albo foreach albo $array[0]

Pozdrawiam


--------------------
$email = filter_var(filter_var($email, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
if($email === false) {
// Houston, we have a problem....
}
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 18:56