Short question regarding a controller instance and referenced template variables..

26 views
Skip to first unread message

Robert G.

unread,
Apr 18, 2012, 6:55:10 AM4/18/12
to Alloy
Hi there,

I'm on my way through the internet exploring different php-frameworks
and paused at Alloy,
as it is small, has a nice syntax and does not seem bloated (yet?..o).
But I have a few little
questions, before going along with it.. o)

How and when does Alloy create a controller for my page !? Is it
created whenever i call an
action from it ?! And what about the next action I call from the same
controller, will that call
create another instance or will the former instance (from the first
action) be used ?!

Does Alloy handle view-data passed by reference ?! I need this for a
message section on the
top of my page (puts out array data) and the data for that array
should be collectable throughout
the complete (h)mvc-triad. Setting a message (adding an element to the
array) in the footer
of my page, should get me the message view (located on top), with that
message included..
The views need to be "on hold", until every request/action is done. At
that point rendering and
echoing view-data should kick in.

It seems to me, view-data passed by reference is not supported my many
frameworks, because
their controller output is often added instantly to the complete
output. Any variable not yet
defined or not yet carrying a sensible value, cannot be used in a
view.

I browsed the Alloy sources and found it makes use of closures for
output handling (&cache?),
I hope my assumption is not false, that it is capable of late/lazy
output of referenced view-data
?!.. o))

A big thank you in advance!
ciao,
Robert

Vance Lucas

unread,
Apr 19, 2012, 11:11:59 AM4/19/12
to allo...@googlegroups.com
To answer your questions:

1) Alloy creates an instance of your Controller when it is dispatched to. It should re-use the same instance on subsequent HMVC calls.

2) Basically, this is how Alloy already works (delayed view rendering - no content is ever output from the Controllers by default - it is explicitly returned), though it may be difficult to pass data to another template directly because they are sandboxed. When you return $this->template('templateName') from a Controller, a new Alloy\View\Template object instance is returned, but is not rendered until the response is sent. The lets Alloy collect any added javascripts and styles and pass them up to the layout template, which is rendered last. These go through a helper and are explicitly extracted into the final layout though, which is why I said it may not be currently possible to pass custom variables to other custom templates directly. I am open for ideas on adding this, though - as it seems like a useful feature. Some sort of static collection of variables that can be set and retrieved in the view templates.

--
Vance Lucas

Robert G.

unread,
Apr 20, 2012, 4:51:14 AM4/20/12
to Alloy
> 1) Alloy creates an instance of your Controller when it is dispatched to.
> It should re-use the same instance on subsequent HMVC calls.

Ok, perfect.. o)

> .., though it may be difficult to pass data to another template
> directly because they are sandboxed.

Uhm, so passing data by reference, would make little sense, because I
cannot
reference to global view data, as such data does not exist, right..
o) ?!

> I am open for ideas on adding this, though - as it seems like a useful feature.
> Some sort of static collection of variables that can be set and retrieved in
> the view templates.

Yes, what you describe is at least possible with FuelPHP e.g. It has 2
methods for setting local/global view data and another 2 methods for
setting
local/global view data by reference (bind() & bind_global() for the
last).

I assumed the majority of frameworks would not be that different at
this corner,
but having some closer looks, teached me better.

I wonder how people get along without basic features, like the one
mentioned
(references/global), i might have "high" requirements, or just don't
know how
to design an application by using any HMVC-framework correctly.. o)

Thank you, I'm a bit smarter by now!.. o)
Robert
Reply all
Reply to author
Forward
0 new messages