2

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!

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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!

1 Comment

"Controller implementation worries about making sure those variables are present in the View" -- sounds like this is doubling the work: if you update View, you also must update Controller. If this does not require updating Model as well than using Model (in strictly Read capability) would make more sense IMO.
0

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.

1 Comment

I don't think that the view should know about the controller, really. It should simply expect (and check for, obviously) the existence of variables that it needs. It doesn't have to care about "who" uses it...if the variables are there, it displays them.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.