Jump to content

Recommended Posts

Hi all!

 

I am having some trouble figuring out the MVC thingy. There is a couple of things that keep bothering me. Mainly about templates.

 

How do I implement different "views" of the same "category". Like I have a news module in my site, and in the news module, I need to list, add and edit news. So that is 3 different views.

 

So, I have situation where I have a frontController, that assigns a pageController, in this situation newsController. The FrontController also assigns newsView.

 

newsController makes the newsView load the layout template. Now it is time to add the "specific template", like add_news, edit_news and so on. So should I create each "view" a separate template file in a "news" folder for example? Or should I have one template file for news, and have a check there what to show?

 

So that way, I will have like a billion different files on a rather small site. It feels rather strange, as I have always had just one file, and in there I have had like an switch case to put up a different view.

 

How is these things done normally? I couldn't figure out from Zend FW nor CodeIgniter. Explanation is very welcomed!

 

Thanks!

 

-NikkiLoveGod

Link to comment
https://forums.phpfreaks.com/topic/132412-v-in-the-mvc-and-templating/
Share on other sites

I need to list, add and edit news. So that is 3 different views.

This is one presentation view and one view with form, IMHO.

 

So should I create each "view" a separate template file in a "news" folder for example?

Yes, because you can easily edit templates this way.

Thanks for a quick reply there Mastodont!

 

So, in newsController I control wether to show the presentation view, which is the listing, and then the add_edit_news view. Then at controller I assign different variables to use at the form action url, and use empty variables to populate the form when just adding a new, and when editing i just give the variables some value. Or should I have some check there whether  the variables are set, then echo them?

 

Does empty variables give a security issue, as they raise a php warning?

 

Then how about if I have some small "info" things, like "Thank you for adding the news!", and I would like them to appear like in front of the "add_edit_news" view. Should I have a separate view for that too? I dont want to copy the add_edit_news view inside this one, so that I dont have to update two things, which is the whole point in these.

 

Thanks again! Sorry to ask "stupid" questions, and make people explain things like to a 5 year old kid :)

Then at controller I assign different variables to use at the form action url, and use empty variables to populate the form when just adding a new, and when editing i just give the variables some value. Or should I have some check there whether  the variables are set, then echo them?

 

There are many ways you can go. Try yourself. I have separate class for form processing and templates with placeholders for individual fields. These placeholders are either deleted (add form) or replaced with current values from table (edit form).

 

small "info" things, like "Thank you for adding the news!", and I would like them to appear like in front of the "add_edit_news" view

 

These things can be also solved by placeholders in template. You have only to track the state of the form and fill or delete placeholders. Or you can have separate messages and send them instead of form.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.