0

I am writing this web project in which one of the views will be having two types of boxes. There is an array and based on type of the values of each item in the array i have to display one or the other box.

Qn is: Should i write the html code for boxes in the controller as two methods or should i write it as two functions and call on it from inside the view itself? Both methods sounds not so good. Your thoughts,suggestions or any ideas for a method outside of two i mentioned above?

Here is a link i saw which closely resembles my thought on writing html code in controller. PHP coding standards

3 Answers 3

1

MVC is a guideline. It's there to help you, if it's hindering you getting the job done then something is wrong.

I'm not sure I understand your question properly, but if you mean that you have to display different HTML depending on the data passed to you during run time, then I'd suggest you package that code in a helper function and call it from your view.

On the other hand, if you mean that you're views are well defined and unchanging, I'd just do the checking in the controller and display the appropriate view.

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

1 Comment

hmm, what i was working on was a custom framework and not a standard framework.However your point is good, thanks! I haven't seen a better answer than writing a helper function.
0

You should follow the common way of dealing with view using MVC guidelines, meaning you should populate a variable with your two functions inside the controller with the values - then inside your view, you should fetch the raw data and display it as you choose.

Comments

0

I'm not sure I understood you completely, but :

  • No HTML code in your controller.

  • If you have 2 different HTML code, and one controller action, then you need 2 views. In your controller, you can then choose which view to use.

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.