Re: [fw-general] Placeholders in View Scripts

2007-11-09 Thread Dan Field


On 9 Nov 2007, at 09:17, Dan Field wrote:

Imagine a fairly typical header, left menu, right content area,  
footer type layout:


you have a _header.phtml file which you include in all view scripts  
and likewise for the footer. You also create the _left_menu.phtml  
view script and include this in the header. All other scripots just  
include the _header and _footer. My question is: How can I go back  
and put some page dependend content into the left menu bar when  
It's been created already by the header?


To answer my own question, it would seem that ViewRenderer and  
Layouts is what I was after.


http://akrabat.com/2007/06/02/extending-viewrenderer-for-layouts/

--
Dan Field <[EMAIL PROTECTED]>   Ffôn/Tel. +44 1970 632 582
Peiriannydd Meddalwedd Software Engineer
Llyfrgell Genedlaethol Cymru   National Library of Wales





[fw-general] Placeholders in View Scripts

2007-11-09 Thread Dan Field
Imagine a fairly typical header, left menu, right content area,  
footer type layout:


you have a _header.phtml file which you include in all view scripts  
and likewise for the footer. You also create the _left_menu.phtml  
view script and include this in the header. All other scripots just  
include the _header and _footer. My question is: How can I go back  
and put some page dependend content into the left menu bar when It's  
been created already by the header?



_header:
foo bar metadata etc...

include('_left_menu')



_left_menu:

  lots of menu related code
  
In here I would like to display content dependent on the action  
being performed

  



_footer:
 

--
Dan Field <[EMAIL PROTECTED]>   Ffôn/Tel. +44 1970 632 582
Peiriannydd Meddalwedd Software Engineer
Llyfrgell Genedlaethol Cymru   National Library of Wales





Re: [fw-general] Placeholders again

2007-08-09 Thread Matthew Weier O'Phinney
-- Dan Rossi <[EMAIL PROTECTED]> wrote
(on Thursday, 09 August 2007, 05:50 PM +1000):
> Hi there, i setup this class, however there is no way to obtain the view 
> class, or any kind of main config . Does it mean the view has to be 
> setup again within the plugin class, doesnt seem so friendly to me, 
> there is no description of how to start the view in something like like 
> this.

Such a plugin makes one of the following assumptions:

  * You've setup the view in your bootstrap or another plugin, and
placed it in Zend_Registry. As such, you're retrieve it from the
registry:

  $view = Zend_Registry::get('view');

  * You're using the ViewRenderer. As such, you can fetch it from the
ViewRenderer using this construct:

  $view = 
Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->view;

  * You want a separate view so that you don't have any variable
pollution bleeding in from previous calls to the view. As such,
you'd instantiate your own view and setup its environment.

  $view = new Zend_View();

Determine which of the above fits your situation and code accordingly.

> class TwoStepPlugin extends Zend_Controller_Plugin_Abstract
> {
> 
>public function dispatchLoopShutdown()
>{
>$response = $this->getResponse();
>$segments = $response->getBody(true);
>// instantiate view in here somewhere...
>$view->assign($segments);
>$content = $view->render('index.phtml');
>$response->setBody($content); // overwrites named segments
>}
> }
> 
> 
> Matthew Weier O'Phinney wrote:
> >-- Dan Rossi <[EMAIL PROTECTED]> wrote
> >(on Tuesday, 07 August 2007, 11:54 PM +1000):
> >  
> >>Hi there im having some problems which ive managed to hack up. Id like 
> >>to be able to render a different template into a template variable 
> >>called {content} so then all i need is one main  index template and each 
> >>controller / action can set a different content placeholder. The only 
> >>way i can do it for the moment is rendering a template to a variable 
> >>$this->view->content, would this be ok  to do ?
> >>
> >>  $this->tpl = $this->view->getEngine();
> >>  $this->tpl->compile('sectionBody.html');
> >>  $this->view->content = 
> >>  $this->tpl->bufferedOutputObject($this->view);
> >>  
> >>  $this->render("index", null, true);
> >>
> >>It basically gets the view engine which is the flexy template engine, 
> >>compiles a section body as a string back to $this->view->content and it 
> >>will display in the variable within the index view script. If there is a 
> >>better way to do this let me know.
> >>
> >
> >One method I and others have used is to render to named segments in the
> >response object -- that's what the second argument to render is. That
> >way, you can collate all your various content from different actions in
> >the response object, and then pull it out to fill in another template.
> >
> >As an example, in your code above, I'd do something like:
> >
> >$this->render('sectionBody', 'section'); // renders to 'section'
> > // response segment
> >
> >And then create a dispatchLoopShutdown plugin:
> >
> >class TwoStepView extends Zend_Controller_Plugin_Abstract
> >{
> >public function dispatchLoopShutdown()
> >{
> >$response = $this->getResponse();
> >$segments = $response->getBody(true);
> >
> >// instantiate view in here somewhere...
> >$view->assign($segments);
> >$content = $view->render('index.phtml');
> >$response->setBody($content); // overwrites named segments
> >}
> >}
> >
> >Hope that makes sense.
> >
> >  
> 

-- 
Matthew Weier O'Phinney
PHP Developer| [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/


Re: [fw-general] Placeholders again

2007-08-09 Thread Dan Rossi
Hi there, i setup this class, however there is no way to obtain the view 
class, or any kind of main config . Does it mean the view has to be 
setup again within the plugin class, doesnt seem so friendly to me, 
there is no description of how to start the view in something like like 
this.


class TwoStepPlugin extends Zend_Controller_Plugin_Abstract
{

   public function dispatchLoopShutdown()
   {
   $response = $this->getResponse();
   $segments = $response->getBody(true);
   // instantiate view in here somewhere...
   $view->assign($segments);
   $content = $view->render('index.phtml');
   $response->setBody($content); // overwrites named segments
   }
}


Matthew Weier O'Phinney wrote:

-- Dan Rossi <[EMAIL PROTECTED]> wrote
(on Tuesday, 07 August 2007, 11:54 PM +1000):
  
Hi there im having some problems which ive managed to hack up. Id like 
to be able to render a different template into a template variable 
called {content} so then all i need is one main  index template and each 
controller / action can set a different content placeholder. The only 
way i can do it for the moment is rendering a template to a variable 
$this->view->content, would this be ok  to do ?


  $this->tpl = $this->view->getEngine();
  $this->tpl->compile('sectionBody.html');
  $this->view->content = $this->tpl->bufferedOutputObject($this->view);
  
  $this->render("index", null, true);


It basically gets the view engine which is the flexy template engine, 
compiles a section body as a string back to $this->view->content and it 
will display in the variable within the index view script. If there is a 
better way to do this let me know.



One method I and others have used is to render to named segments in the
response object -- that's what the second argument to render is. That
way, you can collate all your various content from different actions in
the response object, and then pull it out to fill in another template.

As an example, in your code above, I'd do something like:

$this->render('sectionBody', 'section'); // renders to 'section'
 // response segment

And then create a dispatchLoopShutdown plugin:

class TwoStepView extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopShutdown()
{
$response = $this->getResponse();
$segments = $response->getBody(true);

// instantiate view in here somewhere...
$view->assign($segments);
$content = $view->render('index.phtml');
$response->setBody($content); // overwrites named segments
}
}

Hope that makes sense.

  




Re: [fw-general] Placeholders again

2007-08-07 Thread Matthew Weier O'Phinney
-- Dan Rossi <[EMAIL PROTECTED]> wrote
(on Wednesday, 08 August 2007, 01:09 AM +1000):
> So with these 3 bits
> 
>$view->assign($segments);
> 
> This assigns variables to the view class from the $segments variables 
> correct ie $segments->section and in the main template it would be {section}

I'm not sure how flexy works and how variables are referenced, but yes,
that's what I was thinking.  Zend_View_Abstract::assign() can take an
associative array as an argument (which is what response->getBody(true)
will return -- segment name ->content), and will assign the key/value
pairs to the view object.

>$content = $view->render('index.phtml');
> 
> So the main template is rendered in the plugin instead ?

In the plugin, which will run *after* all actions have been completed
(which is when a dispatchLoopAction() plugin runs), yes -- it renders
the main template, with the various content pieces as assigned from the
response.

>$response->setBody($content); // overwrites named segments
> 
> so the response body is the rendered main template with the sections 
> rendered aswell ?

Correct.

> Matthew Weier O'Phinney wrote:
> > -- Dan Rossi <[EMAIL PROTECTED]> wrote
> > (on Tuesday, 07 August 2007, 11:54 PM +1000):
> >  
> > > Hi there im having some problems which ive managed to hack up. Id like 
> > > to be able to render a different template into a template variable 
> > > called {content} so then all i need is one main  index template and each 
> > > controller / action can set a different content placeholder. The only 
> > > way i can do it for the moment is rendering a template to a variable 
> > > $this->view->content, would this be ok  to do ?
> > >
> > >  $this->tpl = $this->view->getEngine();
> > >  $this->tpl->compile('sectionBody.html');
> > >  $this->view->content = 
> > >  $this->tpl->bufferedOutputObject($this->view);
> > >  
> > >  $this->render("index", null, true);
> > >
> > > It basically gets the view engine which is the flexy template engine, 
> > > compiles a section body as a string back to $this->view->content and it 
> > > will display in the variable within the index view script. If there is a 
> > > better way to do this let me know.
> > >
> >
> > One method I and others have used is to render to named segments in the
> > response object -- that's what the second argument to render is. That
> > way, you can collate all your various content from different actions in
> > the response object, and then pull it out to fill in another template.
> >
> > As an example, in your code above, I'd do something like:
> >
> >$this->render('sectionBody', 'section'); // renders to 'section'
> > // response segment
> >
> > And then create a dispatchLoopShutdown plugin:
> >
> >class TwoStepView extends Zend_Controller_Plugin_Abstract
> >{
> >public function dispatchLoopShutdown()
> >{
> >$response = $this->getResponse();
> >$segments = $response->getBody(true);
> >
> >// instantiate view in here somewhere...
> >$view->assign($segments);
> >$content = $view->render('index.phtml');
> >$response->setBody($content); // overwrites named segments
> >}
> >}
> >
> > Hope that makes sense.

-- 
Matthew Weier O'Phinney
PHP Developer| [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/


Re: [fw-general] Placeholders again

2007-08-07 Thread Dan Rossi

So with these 3 bits

   $view->assign($segments);

This assigns variables to the view class from the $segments variables correct ie 
$segments->section and in the main template it would be {section}

   $content = $view->render('index.phtml');

So the main template is rendered in the plugin instead ?

   $response->setBody($content); // overwrites named segments

so the response body is the rendered main template with the sections rendered 
aswell ?



Matthew Weier O'Phinney wrote:

-- Dan Rossi <[EMAIL PROTECTED]> wrote
(on Tuesday, 07 August 2007, 11:54 PM +1000):
  
Hi there im having some problems which ive managed to hack up. Id like 
to be able to render a different template into a template variable 
called {content} so then all i need is one main  index template and each 
controller / action can set a different content placeholder. The only 
way i can do it for the moment is rendering a template to a variable 
$this->view->content, would this be ok  to do ?


  $this->tpl = $this->view->getEngine();
  $this->tpl->compile('sectionBody.html');
  $this->view->content = $this->tpl->bufferedOutputObject($this->view);
  
  $this->render("index", null, true);


It basically gets the view engine which is the flexy template engine, 
compiles a section body as a string back to $this->view->content and it 
will display in the variable within the index view script. If there is a 
better way to do this let me know.



One method I and others have used is to render to named segments in the
response object -- that's what the second argument to render is. That
way, you can collate all your various content from different actions in
the response object, and then pull it out to fill in another template.

As an example, in your code above, I'd do something like:

$this->render('sectionBody', 'section'); // renders to 'section'
 // response segment

And then create a dispatchLoopShutdown plugin:

class TwoStepView extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopShutdown()
{
$response = $this->getResponse();
$segments = $response->getBody(true);

// instantiate view in here somewhere...
$view->assign($segments);
$content = $view->render('index.phtml');
$response->setBody($content); // overwrites named segments
}
}

Hope that makes sense.

  




Re: [fw-general] Placeholders again

2007-08-07 Thread Matthew Weier O'Phinney
-- Dan Rossi <[EMAIL PROTECTED]> wrote
(on Tuesday, 07 August 2007, 11:54 PM +1000):
> Hi there im having some problems which ive managed to hack up. Id like 
> to be able to render a different template into a template variable 
> called {content} so then all i need is one main  index template and each 
> controller / action can set a different content placeholder. The only 
> way i can do it for the moment is rendering a template to a variable 
> $this->view->content, would this be ok  to do ?
> 
>   $this->tpl = $this->view->getEngine();
>   $this->tpl->compile('sectionBody.html');
>   $this->view->content = $this->tpl->bufferedOutputObject($this->view);
>   
>   $this->render("index", null, true);
> 
> It basically gets the view engine which is the flexy template engine, 
> compiles a section body as a string back to $this->view->content and it 
> will display in the variable within the index view script. If there is a 
> better way to do this let me know.

One method I and others have used is to render to named segments in the
response object -- that's what the second argument to render is. That
way, you can collate all your various content from different actions in
the response object, and then pull it out to fill in another template.

As an example, in your code above, I'd do something like:

$this->render('sectionBody', 'section'); // renders to 'section'
 // response segment

And then create a dispatchLoopShutdown plugin:

class TwoStepView extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopShutdown()
{
$response = $this->getResponse();
$segments = $response->getBody(true);

// instantiate view in here somewhere...
$view->assign($segments);
$content = $view->render('index.phtml');
$response->setBody($content); // overwrites named segments
}
}

Hope that makes sense.

-- 
Matthew Weier O'Phinney
PHP Developer| [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/


[fw-general] Placeholders again

2007-08-07 Thread Dan Rossi
Hi there im having some problems which ive managed to hack up. Id like 
to be able to render a different template into a template variable 
called {content} so then all i need is one main  index template and each 
controller / action can set a different content placeholder. The only 
way i can do it for the moment is rendering a template to a variable 
$this->view->content, would this be ok  to do ?


 $this->tpl = $this->view->getEngine();
  $this->tpl->compile('sectionBody.html');
  $this->view->content = $this->tpl->bufferedOutputObject($this->view);
  
  $this->render("index", null, true);
 

It basically gets the view engine which is the flexy template engine, 
compiles a section body as a string back to $this->view->content and it 
will display in the variable within the index view script. If there is a 
better way to do this let me know.


Re: [fw-general] Placeholders

2007-08-02 Thread Dan Rossi
I just found a work around hack, Ive implemented the smarty / 
HTML_Template_Flexy and templatelite view classes. All i have to do is 
call the getEngine and then compile the template within the controller 
then store the string to load into the template. As i said hack but it 
works for now.



$this->tpl = $this->view->getEngine();
$this->tpl->compile(''body.html');
$this->view->body = $this->tpl->bufferedOutputObject($this->view);

Then in my flexy template

{body:h}


etc.


Still is unsable to get methods from the controller class though ie

{someMethod():h}



Dan Rossi wrote:

Hi thanks for this, it doesnt make sense still though.

It would be nice if they were buffered to variables in the view class, 
so I could just do this in my Flexy or Smarty template {view.body} or 
{view.getBody()}. The main template would be the one rendered first 
when I call render with a specific path so not controller / action 
dependant, render('sitepath/index.html', null, true); in side a 
fooAction method for instance , and then the page specific template is 
buffered to $this->view->body or $this->view->getBody().



Pádraic Brady wrote:

Hi Dan,

A Layout solution has been on the cards for a while now, and such a 
solution is to be decided on in the near future. For the moment you 
can read up on the varying solutions offered by the Layout section of 
Zend_View Enhanced Proposal, and the different strategy of 
Zend_Layout Proposal on the proposals page:

http://framework.zend.com/wiki/display/ZFPROP

A lot of folk are in the same boat awaiting a final accepted 
approach(es) so keep in mind of this and try for something that's 
easy to replace as a temporary measure. Not the greatest advice 
admittedly, but that's the reality for now ;).


Best regards,
Paddy
 
Pádraic Brady

http://blog.astrumfutura.com
http://www.patternsforphp.com


- Original Message 
From: Dan Rossi <[EMAIL PROTECTED]>
To: Zend Framework 
Sent: Wednesday, August 1, 2007 10:21:32 AM
Subject: [fw-general] Placeholders

Hi there, I would like to work out how to use placeholders in my script
templates, so then i only need to use one main template, and then for
each action / controller I can set body content within a html cell or
whatever. I dont like the header / body / footer concept as that doesnt
work at all with designers and is obviouslly a developer concept.


Let me know thanks.



Pinpoint customers 
<http://us.rd.yahoo.com/evt=48250/*http://searchmarketing.yahoo.com/arp/sponsoredsearch_v9.php?o=US2226&cmp=Yahoo&ctv=AprNI&s=Y&s2=EM&b=50>who 
are looking for what you sell. 






Re: [fw-general] Placeholders

2007-08-01 Thread Dan Rossi

Hi thanks for this, it doesnt make sense still though.

It would be nice if they were buffered to variables in the view class, 
so I could just do this in my Flexy or Smarty template {view.body} or 
{view.getBody()}. The main template would be the one rendered first when 
I call render with a specific path so not controller / action dependant, 
render('sitepath/index.html', null, true); in side a fooAction method 
for instance , and then the page specific template is buffered to 
$this->view->body or $this->view->getBody().



Pádraic Brady wrote:

Hi Dan,

A Layout solution has been on the cards for a while now, and such a 
solution is to be decided on in the near future. For the moment you 
can read up on the varying solutions offered by the Layout section of 
Zend_View Enhanced Proposal, and the different strategy of Zend_Layout 
Proposal on the proposals page:

http://framework.zend.com/wiki/display/ZFPROP

A lot of folk are in the same boat awaiting a final accepted 
approach(es) so keep in mind of this and try for something that's easy 
to replace as a temporary measure. Not the greatest advice admittedly, 
but that's the reality for now ;).


Best regards,
Paddy
 
Pádraic Brady

http://blog.astrumfutura.com
http://www.patternsforphp.com


- Original Message 
From: Dan Rossi <[EMAIL PROTECTED]>
To: Zend Framework 
Sent: Wednesday, August 1, 2007 10:21:32 AM
Subject: [fw-general] Placeholders

Hi there, I would like to work out how to use placeholders in my script
templates, so then i only need to use one main template, and then for
each action / controller I can set body content within a html cell or
whatever. I dont like the header / body / footer concept as that doesnt
work at all with designers and is obviouslly a developer concept.


Let me know thanks.



Pinpoint customers 
<http://us.rd.yahoo.com/evt=48250/*http://searchmarketing.yahoo.com/arp/sponsoredsearch_v9.php?o=US2226&cmp=Yahoo&ctv=AprNI&s=Y&s2=EM&b=50>who 
are looking for what you sell. 




Re: [fw-general] Placeholders

2007-08-01 Thread Pádraic Brady
Hi Dan,

A Layout solution has been on the cards for a while now, and such a solution is 
to be decided on in the near future. For the moment you can read up on the 
varying solutions offered by the Layout section of Zend_View Enhanced Proposal, 
and the different strategy of Zend_Layout Proposal on the proposals page:
http://framework.zend.com/wiki/display/ZFPROP

A lot of folk are in the same boat awaiting a final accepted approach(es) so 
keep in mind of this and try for something that's easy to replace as a 
temporary measure. Not the greatest advice admittedly, but that's the reality 
for now ;).

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


- Original Message 
From: Dan Rossi <[EMAIL PROTECTED]>
To: Zend Framework 
Sent: Wednesday, August 1, 2007 10:21:32 AM
Subject: [fw-general] Placeholders

Hi there, I would like to work out how to use placeholders in my script 
templates, so then i only need to use one main template, and then for 
each action / controller I can set body content within a html cell or 
whatever. I dont like the header / body / footer concept as that doesnt 
work at all with designers and is obviouslly a developer concept.


Let me know thanks.







   

Choose the right car based on your needs.  Check out Yahoo! Autos new Car 
Finder tool.
http://autos.yahoo.com/carfinder/

[fw-general] Placeholders

2007-08-01 Thread Dan Rossi
Hi there, I would like to work out how to use placeholders in my script 
templates, so then i only need to use one main template, and then for 
each action / controller I can set body content within a html cell or 
whatever. I dont like the header / body / footer concept as that doesnt 
work at all with designers and is obviouslly a developer concept.



Let me know thanks.