Hello,

I've tried your proposal.

http://framework.zend.com/wiki/pages/viewpage.action?pageId=33071

 I like this way to render multiple view, but all features doesn't work for me. 
The only feature that works for me is "Placeholder" :-(

For my try, I've used ZF 1.0.0-RC3 with a basic layout :

-------------------------------------------
/application
 boostrap.php
 /controllers
 /models
 /views
  /scripts
   /index
    index.phtml
  layout.phtml
  header.phtml
  footer.phtml
/public_html
 index.php
/vendors
 /Zend
------------------------------------------- 

The template that decorates the "ViewRenderer" default View script is 
"layout.phtml", and looks like this :

-------------------------------------------
<head> 
<title>My Application</title> 
</head> 
<body> 
<div id="header"><?php if($this->hasPlaceholder('HEADER')) echo 
$this->getPlaceholder('HEADER'); ?></div>
<div id="main"><?php echo $this->contentForLayout(); ?></div> 
<div id="footer"><?php if($this->hasPlaceholder('FOOTER')) echo 
$this->getPlaceholder('FOOTER'); ?></div> 
</body>
</html>
-------------------------------------------

For my first test, the view script "index/index.phtml" has this content :

-------------------------------------------
<?php $this->appendPlaceholder('HEADER', 'Header');?> 
<?php $this->setPlaceholder('FOOTER', 'Footer');?>
-------------------------------------------

This is the trace for the View render() method :

-- View Render trace --
$name : index/index.phtml
$this->hasLayout : 1
$this->_fileToRender : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/index/index.phtml
$this->_file (before _run()) : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/index/index.phtml
$this->_file (after _run() : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/index/index.phtml
$this->hasLayout : 1
$this->getLayout : layout.phtml
-> Render Layout
--- End render() ---

-- View Render trace --
$name : layout.phtml
$this->hasLayout : 1
$this->_fileToRender : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/layout.phtml
$this->_file (before _run()) : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/layout.phtml
$this->_file (after _run() : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/layout.phtml
$this->hasLayout : 1
$this->getLayout : layout.phtml
-> Return Output
--- End render() ---


Placeholder works... But I would like to do more, so I've changed my view 
script "index/index.phtml" to this :

-------------------------------------------
<?php $this->appendPlaceholder('HEADER', $this->render('header.phtml');?> 
<?php $this->setPlaceholder('FOOTER', 'Footer');?>
-------------------------------------------

That doesn't work... I have a blank page (No error).

This is the trace for the View render() method :

-- View Render trace --
$name : header.phtml
$this->hasLayout : 1
$this->_fileToRender : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/header.phtml
$this->_file (before _run()) : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/header.phtml
$this->_file (after _run() : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/header.phtml
$this->hasLayout : 1
$this->getLayout : layout.phtml
-> Return Output
--- End render() ---

-- View Render trace --
$name : index/index.phtml
$this->hasLayout : 1
$this->_fileToRender : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/index/index.phtml
$this->_file (before _run()) : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/index/index.phtml
$this->_file (after _run() : 
/var/www/sites/_RD/_Zend/fabien/work/application/views/scripts/header.phtml
$this->hasLayout : 1
$this->getLayout : layout.phtml
-> Return Output
--- End render() ---

I notice a strange issue for "$this->_file". The value is different before and 
after the _run method for the second call of render(). 
The Layout is not rendered.

I have try to use "partial", but this time, I got an error (I didn't try to 
solve this).

-------------------------------------------
<?php $this->appendPlaceholder('HEADER', $this->partial('header.phtml');?> 
<?php $this->setPlaceholder('FOOTER', 'Footer');?>
-------------------------------------------

This give me error, "Factory cannot locate module directory". Same error if I 
give module name ("default").

I wonder if I do something bad or not. I continue to try to understand...  If 
you have idea, you're welcome.

Regards,
Fabien

  ----- Original Message ----- 
  From: [EMAIL PROTECTED] 
  To: Pádraic Brady 
  Cc: Zend Framework General 
  Sent: Wednesday, June 13, 2007 2:32 PM
  Subject: Re: [fw-general] Zend_View, Complex View


  Thanks for your answer. I'll wait your ZF proposal code ;-) 
  For the View_Helper, I like this way, I'll adopt it. I don't have yet all of 
ZF functionalities in my brain :-( 
  I just need to change the default xgettext behavior to generate my .po files.

  Regards,
  Fabien (FR)
    ----- Original Message ----- 
    From: Pádraic Brady 
    To: [EMAIL PROTECTED] 
    Cc: Zend Framework General 
    Sent: Wednesday, June 13, 2007 1:01 PM
    Subject: Re: [fw-general] Zend_View, Complex View


    Hey :),

    Glad you enjoyed the blog series. I had a ball writing it too. I'll just 
hit one of your questions for now, will get to others when I have more time. 
When the Wiki is back up, definitely check out the Proposal. I've made some 
changes and did some refactoring since the earlier blog posts. (If you decide 
to use the proposal code, you might want to subclass it so your previous API is 
maintained for older templates).

    On translating, you have a few options. The simplest is to make the 
translation object itself a View parameter so you have:

    <?php echo $this->translate->_("Welcome to the Blog!"); ?>

    Or more accurately, taking security in-depth:

    <?php echo $this->escape($this->translate->_("Welcome to the Blog!")); ?>

    If that looks a little too convoluted, you could add a small View Helper 
which just downsizes the interface a little for the Translation object.

    <?php echo $this->escape($this->translate("Welcome to the Blog!")); ?>

    I'd prefer the second - it's smaller, neater, and makes no assumptions 
about the Translation object's API (since that is refactored to the View 
Helper) making it easier to switch in a different library without the _() 
function defined. If you want to go even further, you can make some assumptions 
about translations, and let the, e.g. Zps_View_Helper_Translate helper 
automatically escape for you unless specified otherwise:

    <?php echo $this->translate("Welcome to the Blog!"); ?>

    Here's a quick skeleton helper as an example (assumes you set the 
Translation object as Zend_View::$translate).

    class Zps_View_Helper_Translate
    {

        public $view = null;

        public function setView(Zend_View_Interface $view)
        {
            if (!isset($view->translate) || !$view->translate instanceof 
Zend_Translate) {
                require_once 'Zend/View/Exception.php';
                throw new Zend_View_Exception('Instance of Zend_Translate is 
not available from this View', $view);
            }
            $this->view = $view;
        }

        public function translate($string, $escape = true)
        {
            if ($escape === false) {
                return $this->view->translate->_($string);
            }
            return $this->view->escape($this->view->translate->_($string));
        }

    }

    The last piece of the puzzle could be integrating sprintf() support so you 
can replace placeholders in the Translation string with dynamic values. For 
example, "Welcome, %1\$s!" (let's say it's "Willkommen, %1\$s" in Deutsche when 
translated) to "Willkommen, Maugrim!".

    <?php echo $this->translate("Welcome, %1\$s!", $this->user->name); ?>

    Results in: "Willkommen, Maugrim!" (n.b. escaping always takes place last).

    Hope this was of help.

    Regards,
    Paddy


    Pádraic Brady
    http://blog.astrumfutura.com
    http://www.patternsforphp.com




    ----- Original Message ----
    From: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
    To: Zend Framework General <[email protected]>
    Sent: Wednesday, June 13, 2007 10:47:31 AM
    Subject: [fw-general] Zend_View, Complex View


    Hi,

    I just start to work with ZF, I'm a beginner, I don't speak english very 
    well, please be indulgent.
    I would like to thank Pádraic Brady about his different articles about 
    complex Views.
    I use your Zend extension (ZPS) which uses "Composite Pattern", and 
"Factory 
    Pattern".

    
http://blog.astrumfutura.com/archives/285-Complex-Views-with-the-Zend-Framework-Part-4-The-View-Factory.html

    I'll read your Zend_View Enhanced proposal with attention.

    I've done some tests and I've some questions, some interrogations.
    I wonder if what I've done can be considered as a good pratice, if I 
respect 
    all concepts.

    I use a "main template" (layout) and sub-views. My "main template" receive 
    by the controller the name of views it must process, and send some data to 
    the views.

    My "main template" looks like this :

    ---- Main template (sample : 'templates/main.php') ----
    <!DOCTYPE html ....
    <html>
    <head>...</head>
    <body>
    <div id="global">
    <div id="header"><?=$this->attach($this->header['tpl'], null, 
    $this->header['params']);?></div>
    <div id="center">
      <div id="content"><?=$this->attach($this->content['tpl'], null, 
    $this->content['params']);?></div>
    </div>
    <div id="footer"><?=$this->attach($this->footer['tpl'], null, 
    $this->footer['params']);?></div>
    </div>
    </body>
    </html>
    ---- / Main template ----


    Some parts of the template are defined by the init() fonction of the 
    controller (ex : $this->header, $this->footer).
    The other parts depends of the asked action.


    ---- Controller (partial code) ----
    public function init(){
        parent::init();
        ...
         $this->view->header = array('tpl' => 'templates/header.php',
                                                      'params' => null);

         $this->view->footer = array('tpl' => 'templates/footer.php',
                                                    'params' => null);
         ...
    }

    public function indexAction(){
        ....
         // Retreived data form Model => $clientResult
        ....
        $this->view->content = array('tpl' => 'index/clients.php',
                                                      'params' => array('data' 
    => $clientResult,
                                                                                
 
      'translate' => $InstanceOfZend_Translate)
                                                     );
        echo $this->view->render('templates/main.php');
    }
    ---- / Controller ----


    I need to translate some static sentences in the views. The controller send 
    an "instance of Zend_Translate" and some data to the views.
    I wonder if it's a good way to work. Send a Instance of Zend_Translate to 
    the view, or create the instance in the views ?


    ---- View ('index/clients.php') ----
    <h1><?=$this->translate->_('Identification');?></h1>
    <ul>
    <?php
    foreach ($this->data as $key => $value){
       echo '<li>'.$value['cli_name'].'</li>';
    }
    ?>
    </ul>
    ---- / View ----

    Thanks for all returned comments.

    Regards,
    Fabien (FR)






----------------------------------------------------------------------------
    Don't be flakey. Get Yahoo! Mail for Mobile and 
    always stay connected to friends.

Reply via email to