Welcome Guest, Not a member yet? Register   Sign In
views using pull instead of push structure
#1

[eluser]Unknown[/eluser]
I am looking to modify CI to use more of a block structure to pull data into views instead of pushing using a controller. Has anyone done this?
#2

[eluser]brianw1975[/eluser]
try thinking of it like this: the controller is pulling the view, with that in mind you can then compare it to the data set, the controller does the logic, pulls the data it wants or needs then pulls the view and applies the data to it. if you think of it from that angle you then realize that what you think of as push is actually a pull experienced from the wrong point of view.
#3

[eluser]Joshua Logsdon[/eluser]
Yeah, just to add in different words... if you're wanting to pull data into blocks from within your view file, you could instead build your blocks (pull your views) in the controller (rendering different views as strings) and then push them out into a final template (which renders your blocks) from the controller.

It sounds like from within your view file you want to do the reverse, doing logic (as in business logic and not display logic) there that would normally be in the controller?

Of course, I could be missing the point and confusing the situation here.
#4

[eluser]Rick Jolly[/eluser]
There is nothing wrong with jpratt's desired approach. By all means, views can get data directly from models, and views can call other code (controllers or pseudo controllers) to return fully prepared view fragments (HMVC).

The advantage of views calling HMVC widgets directly (pull), is that the controller doesn't need to know. So there are less dependencies in your code.

Have a look at wiredesignz's Modular Extensions (HMVC). Here is an example of how to call an HMVC module from your view:
Code:
<?php echo modules::run('module/controller/method', $param, $...); ?>
#5

[eluser]Joshua Logsdon[/eluser]
@jpratt: Hi jpratt, Just know we weren't trying to say there was anything wrong with what you wanted to do or that you couldn't do it. I just wanted to make sure you understand the traditional CI approach and nested views before moving on.

Good luck with it and let us know how it works out for you!
#6

[eluser]Colin Williams[/eluser]
Quote:The advantage of views calling HMVC widgets directly (pull), is that the controller doesn’t need to know

The whole purpose of a controller is to decouple views from the model and views from other views. If that is not your goal, why have the controller at all?
#7

[eluser]wiredesignz[/eluser]
[quote author="Colin Williams" date="1265009693"]The whole purpose of a controller is to decouple views from the model ...[/quote]

That may be your interpretation, but the MVC design pattern states that the controller manages application input and determines output. It does not decouple views from models.

Views can be aware of (coupled to) the model they represent. But models must not be aware of either views or controllers.

A widget (HMVC triad) can be considered as a model for a view partial.

Anything that promotes easy maintainability and re-usability in your application is a good thing.




Theme © iAndrew 2016 - Forum software by © MyBB