codeigniter - MVC confusion passing data from view to model via controller -
if view served controller ok pass data generated in view via post , pass straight model or need go through controller served view , call model controller?
in codeigniter views data controller, demultiplexes / validates parameters , retrieves appropriate data model(s). it's important that:
views output. views not coupled models directly, define html/xml/json/css (either pages, logical parts of pages, or other fragments of output data apis , resources). means not call models views in ci.
controllers proxies. controllers , models not produce output. controllers take , post requests , make calls needed view print result, checking parameters , multiplexing multiple model calls of appropriate data.
models , put data. models should return data in agnostic format: either data objects of model, or more generic (but consistent) hashes of data. cleaner returned model data, less coupling find between views , models (and more able reuse model pieces).
in codeigniter there few places may find overlap:
- javascript ends related views (and may things validation, controller task). can improve moving javascript out of views (works larger pieces, less smaller bits).
- in php, returning hashes (key/value arrays) easier returning objects (less code, reduced type safety). source of coupling.
- shared output stuff finds way controllers (you can avoid moving ci helper libraries).
the goal views unaware of models, except receive data them meets particular specification. controllers , put (they neither generate html output, nor access data directly), , models sql or other forms of getting data , stuffing structured.
Comments
Post a Comment