View Layer update

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

View Layer update

weierophinney
Administrator
Hey, all --

I was sick most of last week, so didn't make as much progress on the
View Layer as I wanted. However, I have a proof of concept working on a
branch of my website code, and will be backporting some changes and
classes to my feature/view-layer ZF2 branch today. It's coming together
well, though the prototyping has raised a few questions/concerns about
the design on my part that I'll be asking for feedback on.

I'd like to do a vote on the RFC soon, but as I'm departing for PHP
Benelux on Wednesday, doing so during this week's IRC meeting is out of
the question as I won't be there to answer questions. As such, I'd like
to propose doing an *additional* IRC meeting _next week_ on Wednesday to
do a vote on the View Layer, and potentially also to finalize the
Console RFC (I'll be talking to Artur about that today).

Is this okay with everyone?

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

Marco Pivetta
Okay for the meeting next Wednesday by me :)
Marco Pivetta

http://twitter.com/Ocramius

http://marco-pivetta.com



On 23 January 2012 17:08, Matthew Weier O'Phinney <[hidden email]> wrote:

> Hey, all --
>
> I was sick most of last week, so didn't make as much progress on the
> View Layer as I wanted. However, I have a proof of concept working on a
> branch of my website code, and will be backporting some changes and
> classes to my feature/view-layer ZF2 branch today. It's coming together
> well, though the prototyping has raised a few questions/concerns about
> the design on my part that I'll be asking for feedback on.
>
> I'd like to do a vote on the RFC soon, but as I'm departing for PHP
> Benelux on Wednesday, doing so during this week's IRC meeting is out of
> the question as I won't be there to answer questions. As such, I'd like
> to propose doing an *additional* IRC meeting _next week_ on Wednesday to
> do a vote on the View Layer, and potentially also to finalize the
> Console RFC (I'll be talking to Artur about that today).
>
> Is this okay with everyone?
>
> --
> Matthew Weier O'Phinney
> Project Lead            | [hidden email]
> Zend Framework          | http://framework.zend.com/
> PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

Constantin Ehrenstein
In reply to this post by weierophinney
+1 for the additional meeting, and thanks for your ongoing efforts.


Constantin

Am 23.01.2012 um 17:08 schrieb Matthew Weier O'Phinney:

Hey, all --

I was sick most of last week, so didn't make as much progress on the
View Layer as I wanted. However, I have a proof of concept working on a
branch of my website code, and will be backporting some changes and
classes to my feature/view-layer ZF2 branch today. It's coming together
well, though the prototyping has raised a few questions/concerns about
the design on my part that I'll be asking for feedback on.

I'd like to do a vote on the RFC soon, but as I'm departing for PHP
Benelux on Wednesday, doing so during this week's IRC meeting is out of
the question as I won't be there to answer questions. As such, I'd like
to propose doing an *additional* IRC meeting _next week_ on Wednesday to
do a vote on the View Layer, and potentially also to finalize the
Console RFC (I'll be talking to Artur about that today).

Is this okay with everyone?

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]




_______________________________

Constantin Ehrenstein
Inhaber/Owner
Freelancer - Consultant - Trainer
_______________________________

tel. +43 (699) 19246456
_______________________________

skiller multimedia services e.U.
Columbusgasse 51/21
1100 Wien
Austria
_______________________________

FN 293145 x (HG Wien)
_______________________________

Jetzt erschienen:
Videotraining zu Zend Framework 1.x



_______________________________

Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

akrabat
In reply to this post by weierophinney

On 23 Jan 2012, at 16:08, Matthew Weier O'Phinney wrote:

>  As such, I'd like
> to propose doing an *additional* IRC meeting _next week_ on Wednesday to
> do a vote on the View Layer, and potentially also to finalize the
> Console RFC (I'll be talking to Artur about that today).
>
> Is this okay with everyone?


Sounds like a good idea to me.

Regards,

Rob...

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

Artur Bodera
In reply to this post by weierophinney
On Mon, Jan 23, 2012 at 5:08 PM, Matthew Weier O'Phinney
<[hidden email]>wrote:

> I'd like to propose doing an *additional* IRC meeting _next week_ on
> Wednesday
>
>
n/p. I'll show up.

A.

--
      __
     /.)\   +48 695 600 936
     \(./   [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

SpiffyJr
This post has NOT been accepted by the mailing list yet.
+1, I'll be there - very interested to see your work.
Kyle S
blogs @ www.spiffyjr.me
github @ www.github.com/spiffyjr
follow @ www.twitter.com/spiffyjr
Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

Tiarê Balbi
This post has NOT been accepted by the mailing list yet.
In reply to this post by weierophinney
Let's go! More one confirmed presence!
Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

weierophinney
Administrator
In reply to this post by weierophinney
As promised, I've got the view-layer branch up-to-date. I've also
updated the RFC with a note at the top about the prototype and some of
my open questions. As a reminder, the RFC is here:

    http://framework.zend.com/wiki/display/ZFDEV2/RFC+-+View+Layer

If you're interested in the view layer, please read, potentially
experiment and play with it, and get me some feedback! :)

-- Matthew Weier O'Phinney <[hidden email]> wrote
(on Monday, 23 January 2012, 10:08 AM -0600):

> Hey, all --
>
> I was sick most of last week, so didn't make as much progress on the
> View Layer as I wanted. However, I have a proof of concept working on a
> branch of my website code, and will be backporting some changes and
> classes to my feature/view-layer ZF2 branch today. It's coming together
> well, though the prototyping has raised a few questions/concerns about
> the design on my part that I'll be asking for feedback on.
>
> I'd like to do a vote on the RFC soon, but as I'm departing for PHP
> Benelux on Wednesday, doing so during this week's IRC meeting is out of
> the question as I won't be there to answer questions. As such, I'd like
> to propose doing an *additional* IRC meeting _next week_ on Wednesday to
> do a vote on the View Layer, and potentially also to finalize the
> Console RFC (I'll be talking to Artur about that today).
>
> Is this okay with everyone?

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

Marc Bennewitz (private)
Looks great to me !

Point 1: JSON-P <> JSON+Layout:
For me a JSON-P isn't simply a layout of a JSON data structure because
the "padding" if vary specific.
A layout of a JSON could something like {"result": __RESULT__}
-> That means it should be two different view-models and the available
options are specific to it.
-> Option setters/getters would be very helpful

Example:
|$result| |= ||new| |JsonpModel();
$result->setVariable('result', 1);
|$result->setPaddingFunction('functionCall');
return $result; // functionCall({"result":1});

Point 2: How-to disable output buffering from in an action
Output buffering has some pros but also cons and I often need to disable
it mostly to speed-up server response time.
-> What is a good and simple way to disable/enable it or will it
be disabled automatically if layout is disabled ?

Greetings
Marc

On 24.01.2012 22:18, Matthew Weier O'Phinney wrote:

> As promised, I've got the view-layer branch up-to-date. I've also
> updated the RFC with a note at the top about the prototype and some of
> my open questions. As a reminder, the RFC is here:
>
>     http://framework.zend.com/wiki/display/ZFDEV2/RFC+-+View+Layer
>
> If you're interested in the view layer, please read, potentially
> experiment and play with it, and get me some feedback! :)
>
> -- Matthew Weier O'Phinney <[hidden email]> wrote
> (on Monday, 23 January 2012, 10:08 AM -0600):
>> Hey, all --
>>
>> I was sick most of last week, so didn't make as much progress on the
>> View Layer as I wanted. However, I have a proof of concept working on a
>> branch of my website code, and will be backporting some changes and
>> classes to my feature/view-layer ZF2 branch today. It's coming together
>> well, though the prototyping has raised a few questions/concerns about
>> the design on my part that I'll be asking for feedback on.
>>
>> I'd like to do a vote on the RFC soon, but as I'm departing for PHP
>> Benelux on Wednesday, doing so during this week's IRC meeting is out of
>> the question as I won't be there to answer questions. As such, I'd like
>> to propose doing an *additional* IRC meeting _next week_ on Wednesday to
>> do a vote on the View Layer, and potentially also to finalize the
>> Console RFC (I'll be talking to Artur about that today).
>>
>> Is this okay with everyone?
Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

weierophinney
Administrator
-- Marc Bennewitz <[hidden email]> wrote
(on Tuesday, 24 January 2012, 11:03 PM +0100):

> Looks great to me !
>
> Point 1: JSON-P <> JSON+Layout:
> For me a JSON-P isn't simply a layout of a JSON data structure because
> the "padding" if vary specific.
> A layout of a JSON could something like {"result": __RESULT__}
> -> That means it should be two different view-models and the available
> options are specific to it.
> -> Option setters/getters would be very helpful
>
> Example:
> |$result| |= ||new| |JsonpModel();
> $result->setVariable('result', 1);
> |$result->setPaddingFunction('functionCall');
> return $result; // functionCall({"result":1});

These are good points -- but it was really simply a potential
illustration/use case. I like the idea you have for the JsonpModel,
however!

> Point 2: How-to disable output buffering from in an action
> Output buffering has some pros but also cons and I often need to disable
> it mostly to speed-up server response time.
> -> What is a good and simple way to disable/enable it or will it
> be disabled automatically if layout is disabled ?

The proposal doesn't address how the PhpRenderer should work, to be
honest. If that's an option you would like to add, please feel free to
do a PR for that. It will need to take into account whether or not
there's a stack, though the assumption with a stack is that you will
likely render to placeholders, and have the last template in the stack
consume that rendered content. In such cases, the placeholder
functionality will need to retain ob support, but the main
PhpRenderer::render() method would not need it.


> On 24.01.2012 22:18, Matthew Weier O'Phinney wrote:
> > As promised, I've got the view-layer branch up-to-date. I've also
> > updated the RFC with a note at the top about the prototype and some of
> > my open questions. As a reminder, the RFC is here:
> >
> >     http://framework.zend.com/wiki/display/ZFDEV2/RFC+-+View+Layer
> >
> > If you're interested in the view layer, please read, potentially
> > experiment and play with it, and get me some feedback! :)
> >
> > -- Matthew Weier O'Phinney <[hidden email]> wrote
> > (on Monday, 23 January 2012, 10:08 AM -0600):
> >> Hey, all --
> >>
> >> I was sick most of last week, so didn't make as much progress on the
> >> View Layer as I wanted. However, I have a proof of concept working on a
> >> branch of my website code, and will be backporting some changes and
> >> classes to my feature/view-layer ZF2 branch today. It's coming together
> >> well, though the prototyping has raised a few questions/concerns about
> >> the design on my part that I'll be asking for feedback on.
> >>
> >> I'd like to do a vote on the RFC soon, but as I'm departing for PHP
> >> Benelux on Wednesday, doing so during this week's IRC meeting is out of
> >> the question as I won't be there to answer questions. As such, I'd like
> >> to propose doing an *additional* IRC meeting _next week_ on Wednesday to
> >> do a vote on the View Layer, and potentially also to finalize the
> >> Console RFC (I'll be talking to Artur about that today).
> >>
> >> Is this okay with everyone?

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

gargoyle-3
Anyone got a working example? I seem to be getting close, but not sure how to configure it all?

Wouldn't mind having a proper play before next week.

Paul

On 24 Jan 2012, at 22:54, Matthew Weier O'Phinney wrote:

> -- Marc Bennewitz <[hidden email]> wrote
> (on Tuesday, 24 January 2012, 11:03 PM +0100):
>> Looks great to me !
>>
>> Point 1: JSON-P <> JSON+Layout:
>> For me a JSON-P isn't simply a layout of a JSON data structure because
>> the "padding" if vary specific.
>> A layout of a JSON could something like {"result": __RESULT__}
>> -> That means it should be two different view-models and the available
>> options are specific to it.
>> -> Option setters/getters would be very helpful
>>
>> Example:
>> |$result| |= ||new| |JsonpModel();
>> $result->setVariable('result', 1);
>> |$result->setPaddingFunction('functionCall');
>> return $result; // functionCall({"result":1});
>
> These are good points -- but it was really simply a potential
> illustration/use case. I like the idea you have for the JsonpModel,
> however!
>
>> Point 2: How-to disable output buffering from in an action
>> Output buffering has some pros but also cons and I often need to disable
>> it mostly to speed-up server response time.
>> -> What is a good and simple way to disable/enable it or will it
>> be disabled automatically if layout is disabled ?
>
> The proposal doesn't address how the PhpRenderer should work, to be
> honest. If that's an option you would like to add, please feel free to
> do a PR for that. It will need to take into account whether or not
> there's a stack, though the assumption with a stack is that you will
> likely render to placeholders, and have the last template in the stack
> consume that rendered content. In such cases, the placeholder
> functionality will need to retain ob support, but the main
> PhpRenderer::render() method would not need it.
>
>
>> On 24.01.2012 22:18, Matthew Weier O'Phinney wrote:
>>> As promised, I've got the view-layer branch up-to-date. I've also
>>> updated the RFC with a note at the top about the prototype and some of
>>> my open questions. As a reminder, the RFC is here:
>>>
>>>    http://framework.zend.com/wiki/display/ZFDEV2/RFC+-+View+Layer
>>>
>>> If you're interested in the view layer, please read, potentially
>>> experiment and play with it, and get me some feedback! :)
>>>
>>> -- Matthew Weier O'Phinney <[hidden email]> wrote
>>> (on Monday, 23 January 2012, 10:08 AM -0600):
>>>> Hey, all --
>>>>
>>>> I was sick most of last week, so didn't make as much progress on the
>>>> View Layer as I wanted. However, I have a proof of concept working on a
>>>> branch of my website code, and will be backporting some changes and
>>>> classes to my feature/view-layer ZF2 branch today. It's coming together
>>>> well, though the prototyping has raised a few questions/concerns about
>>>> the design on my part that I'll be asking for feedback on.
>>>>
>>>> I'd like to do a vote on the RFC soon, but as I'm departing for PHP
>>>> Benelux on Wednesday, doing so during this week's IRC meeting is out of
>>>> the question as I won't be there to answer questions. As such, I'd like
>>>> to propose doing an *additional* IRC meeting _next week_ on Wednesday to
>>>> do a vote on the View Layer, and potentially also to finalize the
>>>> Console RFC (I'll be talking to Artur about that today).
>>>>
>>>> Is this okay with everyone?
>
> --
> Matthew Weier O'Phinney
> Project Lead            | [hidden email]
> Zend Framework          | http://framework.zend.com/
> PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>


--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

weierophinney
Administrator
-- Paul Court <[hidden email]> wrote
(on Wednesday, 25 January 2012, 09:13 PM +0000):
> Anyone got a working example? I seem to be getting close, but not sure how to configure it all?
>
> Wouldn't mind having a proper play before next week.

I did initial prototyping/testing on my sandbox repo:

    git clone git://mwop.net/zf2sandbox.git

Then select the feature/view-layer branch.


> On 24 Jan 2012, at 22:54, Matthew Weier O'Phinney wrote:
>
> > -- Marc Bennewitz <[hidden email]> wrote
> > (on Tuesday, 24 January 2012, 11:03 PM +0100):
> >> Looks great to me !
> >>
> >> Point 1: JSON-P <> JSON+Layout:
> >> For me a JSON-P isn't simply a layout of a JSON data structure because
> >> the "padding" if vary specific.
> >> A layout of a JSON could something like {"result": __RESULT__}
> >> -> That means it should be two different view-models and the available
> >> options are specific to it.
> >> -> Option setters/getters would be very helpful
> >>
> >> Example:
> >> |$result| |= ||new| |JsonpModel();
> >> $result->setVariable('result', 1);
> >> |$result->setPaddingFunction('functionCall');
> >> return $result; // functionCall({"result":1});
> >
> > These are good points -- but it was really simply a potential
> > illustration/use case. I like the idea you have for the JsonpModel,
> > however!
> >
> >> Point 2: How-to disable output buffering from in an action
> >> Output buffering has some pros but also cons and I often need to disable
> >> it mostly to speed-up server response time.
> >> -> What is a good and simple way to disable/enable it or will it
> >> be disabled automatically if layout is disabled ?
> >
> > The proposal doesn't address how the PhpRenderer should work, to be
> > honest. If that's an option you would like to add, please feel free to
> > do a PR for that. It will need to take into account whether or not
> > there's a stack, though the assumption with a stack is that you will
> > likely render to placeholders, and have the last template in the stack
> > consume that rendered content. In such cases, the placeholder
> > functionality will need to retain ob support, but the main
> > PhpRenderer::render() method would not need it.
> >
> >
> >> On 24.01.2012 22:18, Matthew Weier O'Phinney wrote:
> >>> As promised, I've got the view-layer branch up-to-date. I've also
> >>> updated the RFC with a note at the top about the prototype and some of
> >>> my open questions. As a reminder, the RFC is here:
> >>>
> >>>    http://framework.zend.com/wiki/display/ZFDEV2/RFC+-+View+Layer
> >>>
> >>> If you're interested in the view layer, please read, potentially
> >>> experiment and play with it, and get me some feedback! :)
> >>>
> >>> -- Matthew Weier O'Phinney <[hidden email]> wrote
> >>> (on Monday, 23 January 2012, 10:08 AM -0600):
> >>>> Hey, all --
> >>>>
> >>>> I was sick most of last week, so didn't make as much progress on the
> >>>> View Layer as I wanted. However, I have a proof of concept working on a
> >>>> branch of my website code, and will be backporting some changes and
> >>>> classes to my feature/view-layer ZF2 branch today. It's coming together
> >>>> well, though the prototyping has raised a few questions/concerns about
> >>>> the design on my part that I'll be asking for feedback on.
> >>>>
> >>>> I'd like to do a vote on the RFC soon, but as I'm departing for PHP
> >>>> Benelux on Wednesday, doing so during this week's IRC meeting is out of
> >>>> the question as I won't be there to answer questions. As such, I'd like
> >>>> to propose doing an *additional* IRC meeting _next week_ on Wednesday to
> >>>> do a vote on the View Layer, and potentially also to finalize the
> >>>> Console RFC (I'll be talking to Artur about that today).
> >>>>
> >>>> Is this okay with everyone?
> >
> > --
> > Matthew Weier O'Phinney
> > Project Lead            | [hidden email]
> > Zend Framework          | http://framework.zend.com/
> > PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
> >
> > --
> > List: [hidden email]
> > Info: http://framework.zend.com/archives
> > Unsubscribe: [hidden email]
> >
> >
>
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

akrabat
In reply to this post by gargoyle-3
Hi,

I now have a working example at https://github.com/akrabat/ShowRecord/tree/view-layer-changes

I had to modify Matthew's code a little to get it working. My changes are here:
https://github.com/akrabat/zf2/compare/weierophinney:feature/view-layer...feature/view-layer

The key change I had to make was to render the templates that had been enqueued to the Renderer in a LIFO order. The original code uses FIFO, but for me that resulted in the layout view script being rendered before the action view script. I also introduced a default extension (.phtml) so that I didn't' have to set the extension in the "template" parameter of the ViewModel that is returned from the action method in the controller.

i.e. I want to do:

class IndexController extends ActionController
{
    public function indexAction()
    {
        $result = new ViewModel();
        $result->setOptions(array(
            'template'   => 'index/index',
            'use_layout' => true,
        ));
        return $result;
    }
}
Hence, we need to add .phtml somewhere else.

I also added a getView() method to DefaultRenderingStrategy, but it turns out that I didn't need it after all :)


In terms of the application code, I used DI to set everything up in module/Application/config/module.config.php. The key things here is that I had to create a definition for Zend\View\View::addRenderer() in order to inject the PhpRenderer. For some reason when I did this, I then had to inject the script_paths into the Zend\View\Resolver\TemplatePathStack rather than via the PhpRenderer. This seems more logical though, so that's fine.

Quite a lot of config in module.config.php though :)


I also derived my own Application/View/RenderingStrategy class which extends Zend\Mvc\View\DefaultRenderingStrategy in order to set the default layout that I wanted. Also, this is a good place to initialise the view helpers that need info from the application:

class RenderingStrategy extends DefaultRenderingStrategy
{
    protected $defaultLayout = 'layout/layout';
   
    /**
     * Render the view
     *
     * @param  MvcEvent $e
     * @return \Zend\Stdlib\ResponseDescription
     */
    public function render($e)
    {
        $request = $e->getRequest();

        $renderer = $this->view->getRenderer('Zend\View\PhpRenderer');
        $renderer->plugin('basePath')->setBasePath($request->getBaseUrl());

        $renderer->doctype('HTML5');

        $renderer->plugin('url')->setRouter($e->getRouter());

        return parent::render($e);
    }    
}



Lastly, I updated the Application's Module class to add the RenderingStrategy to the app's event manger :

    public function initializeView($e)
    {
        $application = $e->getParam('application');
        $locator     = $application->getLocator();

        // Attach the rendering strategy to listen to the application's events
        $renderingStrategy = $locator->get('Application\View\RenderingStrategy');
        $application->events()->attachAggregate($renderingStrategy);
    }

This is now nice and simple which I like.


I have no idea if this is the way that Matthew envisaged that it should be done, but it's working and I'm sure he'll be along soon to explain where I went wrong!

Regards,

Rob...


On 25 Jan 2012, at 21:13, Paul Court wrote:

> Anyone got a working example? I seem to be getting close, but not sure how to configure it all?
>
> Wouldn't mind having a proper play before next week.
>
> Paul


--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

weierophinney
Administrator
-- Rob Allen <[hidden email]> wrote
(on Sunday, 29 January 2012, 01:02 PM +0000):
> I now have a working example at https://github.com/akrabat/ShowRecord/tree/view-layer-changes
>
> I had to modify Matthew's code a little to get it working. My changes are here:
> https://github.com/akrabat/zf2/compare/weierophinney:feature/view-layer...feature/view-layer
>
> The key change I had to make was to render the templates that had been
> enqueued to the Renderer in a LIFO order. The original code uses FIFO,
> but for me that resulted in the layout view script being rendered
> before the action view script.

Arggghhh.. I thought I'd committed that change!

> I also introduced a default extension (.phtml) so that I didn't' have
> to set the extension in the "template" parameter of the ViewModel that
> is returned from the action method in the controller.

I did this myself by using the TemplateMapResolver; we should likely do
some work in the TemplatePathStack to append the .phtml suffix, as the
resolver is the appropriate place for this to happen.

<snip>

> I also added a getView() method to DefaultRenderingStrategy, but it
> turns out that I didn't need it after all :)

Nope -- because the individual event listeners end up receiving it. :)

> In terms of the application code, I used DI to set everything up in
> module/Application/config/module.config.php. The key things here is
> that I had to create a definition for Zend\View\View::addRenderer() in
> order to inject the PhpRenderer. For some reason when I did this, I
> then had to inject the script_paths into the
> Zend\View\Resolver\TemplatePathStack rather than via the PhpRenderer.
> This seems more logical though, so that's fine.

Yes -- this is the better place to do it. I actually ran into this when
preparing my ZF2 workshop for PHPBenelux last week; passing the paths to
the PhpRenderer means that you are effectively hard-coding which
resolver to use. It's better to configure the individual resolver
classes, and then via DI choose which resolver you plan to use. This
also makes it easier to override where the templates resolve. :)

> Quite a lot of config in module.config.php though :)

I have some ideas about this, in part from looking at configuration from
a re-usability and override-ability standpoint. I'll bring those ideas
up in a separate thread, though.

> I also derived my own Application/View/RenderingStrategy class which
> extends Zend\Mvc\View\DefaultRenderingStrategy in order to set the
> default layout that I wanted. Also, this is a good place to initialise
> the view helpers that need info from the application:

Oh, that's a very interesting usage! I quite like that!

> class RenderingStrategy extends DefaultRenderingStrategy
> {
>     protected $defaultLayout = 'layout/layout';
>    
>     /**
>      * Render the view
>      *
>      * @param  MvcEvent $e
>      * @return \Zend\Stdlib\ResponseDescription
>      */
>     public function render($e)
>     {
>         $request = $e->getRequest();
>
>         $renderer = $this->view->getRenderer('Zend\View\PhpRenderer');
>         $renderer->plugin('basePath')->setBasePath($request->getBaseUrl());
>
>         $renderer->doctype('HTML5');
>
>         $renderer->plugin('url')->setRouter($e->getRouter());
>
>         return parent::render($e);
>     }    
> }
>
>
>
> Lastly, I updated the Application's Module class to add the
> RenderingStrategy to the app's event manger :
>
>     public function initializeView($e)
>     {
>         $application = $e->getParam('application');
>         $locator     = $application->getLocator();
>
>         // Attach the rendering strategy to listen to the application's events
>         $renderingStrategy = $locator->get('Application\View\RenderingStrategy');
>         $application->events()->attachAggregate($renderingStrategy);
>     }
>
> This is now nice and simple which I like.

This is exactly how I did it as well.

> I have no idea if this is the way that Matthew envisaged that it
> should be done, but it's working and I'm sure he'll be along soon to
> explain where I went wrong!

Nope -- in almost all ways, it's how I was using it while prototyping.
As noted, I have a few things I want to address for the final version,
and I'll raise ideas in separate threads this week.

Thanks for taking the time to write about your experiences and what
worked and what raised questions for you!


> On 25 Jan 2012, at 21:13, Paul Court wrote:
>
> > Anyone got a working example? I seem to be getting close, but not sure how to configure it all?
> >
> > Wouldn't mind having a proper play before next week.
> >
> > Paul
>
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: View Layer update

BullfrogBlues
This post has NOT been accepted by the mailing list yet.
In reply to this post by weierophinney
Please remove plugin magic method invocation, some consistency please:

$this->headStyle();
$this->plugin('headStyle');

Please kill the first way of doing it. The zf2 examples use both, no consistency. Unless the first style of doing it is killed, there will never be any consistency.

The very latest commit on the skelton-app is just one example, see line. 75 $this->doctype(): https://github.com/zendframework/ZendSkeletonApplication/commit/fc842fa8399e83f667574c19eecb701de22dca3a

Kill it and kill it today.

This applies not just to view plugins. My opinion is that zf2 should do things one way, and one way only, if for the sake of consistency then nothing else. Let the developer decide to do it differently.