Models Views and Controllers jobs

First, I know there are lot of answers about MVC but I need some more-specific ansewer based on my probably wrong understanding of MVC.

I’ve already read this very good answer (Explain Model View Controller) but I still need some clarification.

I need to understand if I’ve understood how MVC works because I’m using it in a kind of MVC framework I’m developing.

  • I have the views that are at the moment just “stupid” templates
  • The models that are “things” that fetch data from database (or other sources) and transform them in arrays passed to the views.
  • The controllers that are mostly ajax javascript scripts and observers for buttons and other user events and PHP scripts that are called by the Ajax scripts when I need to perform server-side operations like SQL updates, inserts etc.

So my “MVC understanding” makes my app works in this way:

I open my index that loads the viewsloader(model), this one loads the contents calling the contentsloader(model) that calls some other script depending by the view the user is requesting.
Then when all the data is loaded in a single array, the viewsloader(model) uses it to render the requested view and passes it to the user.

Now the user can click some button (for example a “view contacts” button) and under the hood my contactslistener(controller) calls the contactsloader(model) to load the contacts list, the array provided by the contactsloader(model) passed trhough the contactslistener(controller) which injects it in the view.


I think I have serious problems with the MVC model, looks like the controllers are doing too different things. Probably I should put the observers/listeners in the views part and use controllers just to load contents provided by the models.

  • Are the models dedicated just to data fetching and organization (for example, fetch from database and put it in array organizing it with the right structure)?
  • Are the controllers thought for handle user events or should I use views for this purpose? Should I use them to query the models and inject the answers into the views?
  • Are the views just stupid templates or should I put there some business logic like event listeners? Following what I’ve read I should put the entire interface-side scripts here and put only (client/server)-side scripts in controllers. But in this case I’ve not idea about what a controller should do…

2

Thanks to Euphoric for the very useful answer, I’ve got what he means but I’ve even found a very good article about MVC used besides Ajax.

It’s not “the bible of MVC” but I’ve used it to understand the functions that each part of MVC should do.

This is the chart I’ve found useful, edited a bit by meself:
enter image description here

I’ve added the HTTP response and requests from and to static-HTML because using a template engine like Mustache there aren’t the problems described in the article I link below:

https://blog.glyphobet.net/essay/153

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật