views:

97

answers:

4

Hi people,

At this time I want to build a MVC framework. Everything is going fine but now I got a problem between controller and view. Hope you can help me.

My MVC is not so different from MVC, it uses the same concept, but technically I got an issue. The question is: how to take data from the controller once the view is loaded?

Bear in mind that in views you don't use globals or something like, every parameter (like DB reply, etc) must be passed to the view and the view uses it directly (like... for example, CodeIgniter).

I don't know how to say it better, I'm sorry if you don't understand me. But hope you can!

+1  A: 

You must pass the view a reference to the controller object or the view must use static methods on a related controller class. The view then calls methods on the controller to display results. The view also submits form data to the controller through the controller object or class.

MattSmith
+2  A: 

You probably want to bind a list of variables to the view's namespace.

You could peruse Kohana's View class for some inspiration or ideas.

alex
+2  A: 

The point behind the MVC framework is that a View should not need to be aware of the Controller and it's implementation. A View should just have a list of variables that it needs to be present to render correctly, and the Controller implementation worries about making sure those variables are present in the View.

Might I ask why you are designing your own MVC framework though? There are plenty of fantastic solutions out there, I would personally recommend you try out CakePHP, I've used it to ship several commercial products and I swear by it!

Sam Day
A: 

If your View implementation uses a template engine, there is usually a mechanism for adding arbitrary key/value data to the template's scope. If you haven't progressed to that point it's probably worth thinking about a similar strategy.

Jeff Standen