Hi Cap'n Fly,

Me maties tell me the proposal code has a few minor issues in configuring new 
View objects - a lot of the code is pre-ViewRenderer so I shuffled some things 
into a Zend_View_Factory. I'll add an examples directory to the repository 
during the week to illustrate some usage.

In the meantime if you care to forward your working files I'll look at what 
went wrong. I would also suggest looking through the unit tests in case you're 
missing a setup test - for example, Zend_View_Factory can be setup by passing 
it a Module Directory setting to where your "default" and other Modules are 
located (it uses this to apply the ViewRenderer style convention in setting 
Zend_View's base-path.

Finally, you might want to look into Zend_View_Factory and check where to 
attach a configuration file in the bootstrap to it. The current system defaults 
to a specific convention which your code doesn't appear to follow. For the 
moment, when testing this, stick with the Modular Directory layout from the ZF 
manual (i.e. /views is a subdirectory of a module. e.g. /default/views, 
/blog/views). This is the single area in the code which can quite truthfully be 
called broken - it's incomplete and is likely causing at least some of your 
problems as you move away from that convention.

The configuration file option would likely work best. I'll be working on that 
area later in the week so it's less broken.

Bear in mind the repository code is meant to illustrate the ideas - it's not 
intended as production quality :).

Many thanks for the feedback!

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


----- Original Message ----
From: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
To: Pádraic Brady <[EMAIL PROTECTED]>
Cc: Zend Framework General <[email protected]>
Sent: Monday, June 25, 2007 5:30:40 PM
Subject: Re: [fw-general] Zend_View, Complex View



 
DIV {
MARGIN:0px;}



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.





 
____________________________________________________________________________________
No need to miss a message. Get email on-the-go 
with Yahoo! Mail for Mobile. Get started.
http://mobile.yahoo.com/mail 

Reply via email to