-
Notifications
You must be signed in to change notification settings - Fork 66
MVC: Information Flow
In a Roxy MVC (or hybrid) application, information flows from controller -> model -> controller -> view -> layout. It's pretty easy to send information along that direction -- this page illustrates how.
When a request comes in, the controller's job is to pass any input parameters along to the model. It does this by using the req library to get any HTTP parameters, then calling the appropriate model functions.
(: example - in the controller :)
s:get-data(req:get("q"))
When the model returns a value, the controller can use the ch:add-value() function to make it available to the view. To extend the above example:
(: example - in the controller :)
ch:add-value("data", s:get-data(req:get("q")))
All the controller calls to ch:add-value() build up some data that is made available to the view through the vh:get() function.
(: example - in the view :)
declare variable $data := vh:get("data");
The view can also add information for the layout.
(: example - in the view :)
vh:add-value("additional-js",
<scripts xmlns="http://www.w3.org/1999/xhtml">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="/js/app.js" type='text/javascript'></script>
</scripts>/*
The layout picks this up the same way that the view gets information from the controller:
(: example - in the layout :)
declare variable $additional-js := vh:get("additional-js");
Note that the Layout can also call vh:get() on values set by the controller.