ZF2 [ beta5 ] widget architecture with view helpers

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

ZF2 [ beta5 ] widget architecture with view helpers

miki
Hi everybody
I really like the View Helper concept but I want to create some kind of a widget architecture.
I've created some test classes as a proof of concept.
I have inherited from the Abstract View Helper class to create some Widget Classes. So far so good.
But then I got some problems, such as for example if I wanted to nest widgets.

After this I looked for other solutions

My new idea is to create a widget element like this pseudo code below

<w:my_widget>
        <w:label value="{title}">
        <w:my_other_widget>www.test.com<w:my_other_widget>
</w:my_widget>

To get this to work i have to parse the content and create the widgets and add them together.
Here is some pseudo code of the Parser

$my_other_widget = new my_other_widget();
$my_other_widget->setContent($content); -> content is "www.test.com"

$my_widget = new my_widget();
$my_widget->addChild($my_other_widget,$key);
$my_widget->setContent($content);

This code has no sense, it is only an idea.

Now to my question
what is the best possibility to parse the output

I have found 3 options so far, another important argument is that I need to have access to view variables

1. To program a similar "Widget" ViewHelper as the "PlaceHolder" ViewHelper

<?php $this->widget(array('title' => $my_title))->captureStart(); ?>
<w:my_widget>
        <w:label value="{title}">
        <w:my_other_widget>www.test.com<w:my_other_widget>
</w:my_widget>
<?php $this->widget()->captureEnd(); ?>

And parse the output and translate directly into HTML and echo it at the captureEnd() method, but this method is a little ugly

2. Inherit from the PhpRenderer and parsing the output in the render () method
    qustion:
Do I need to develop my own resolver and rendering Startegy when i inherit from Phprenderer or is it an easy task to do?


3. Injecting a filter chain object into the Phprenderer with setFilterChain () method
    I like to test this approach but i havent found a solution to get the phprender instance.
    Question:
How can i inject an output filter into the Phprenderer instance ?  do i need to use a factoriy in the service_manager?

What is the best approach to go for ?
Are there any better/faster ways to parse the output ?

I would love to here some suggestions

Best regards
Michael Haessig
Reply | Threaded
Open this post in threaded view
|

Re: ZF2 [ beta5 ] widget architecture with view helpers

HHGAG
This post has NOT been accepted by the mailing list yet.
This post was updated on .
Hi,

take a look at this thread: http://zend-framework-community.634137.n4.nabble.com/Dynamic-views-in-ZF2-td4655337.html

That could also solve your problem.
Hasan H. Gürsoy (HHGAG)
Reply | Threaded
Open this post in threaded view
|

Re: ZF2 [ beta5 ] widget architecture with view helpers

miki
This post has NOT been accepted by the mailing list yet.

thanks for the quick reply.
i've already read this thread. It describes how to put some placeholder in the layout and render them each.
But in my case i don't know how to use this since i want to bo able to use widgets in the differnt views an nest them and create them dynamic after parsing.

So my main question is what is the best way to parse the view.