sKunKbad Posted April 15, 2009 Share Posted April 15, 2009 I'm exploring the Kohana PHP framework, and I can see how views, controllers, and the template work together, but I haven't had time to figure out the use of models. I'm used to procedural PHP, and while I understand and use OOP, MVC of Kohana takes me to a new level of feeling stupid. I really don't understand the need for MVC at all. Quote Link to comment https://forums.phpfreaks.com/topic/154245-help-me-understand-why-mvc-is-beneficial/ Share on other sites More sharing options...
Mchl Posted April 15, 2009 Share Posted April 15, 2009 Theoretically you could take any part of MVC and put something else in its place without changing other parts. It's easiest to imagine when we consider View. You could have one View that generates fancy, colourful, CSS styled HTML Web pages for traditional browsers, and another that generates plain Web pages for mobile devices with low bandwidth. Both would be using same Models and same Controllers. You don't have to introduce any changes into Models or Controllers if you want to switch the view. You can also easily add another view for generating RSS, then another for.. .something else... On the Model side one could easily imagine the need to switch from MySQL to Oracle to PostgreSQL... With MVC pattern switching a database engine should not require any changes to Controllers or Views. Quote Link to comment https://forums.phpfreaks.com/topic/154245-help-me-understand-why-mvc-is-beneficial/#findComment-810926 Share on other sites More sharing options...
sKunKbad Posted April 15, 2009 Author Share Posted April 15, 2009 Those are helpful facts about MVC. Thanks for your reply. Would you personally use MVC in all projects, regardless of size? Quote Link to comment https://forums.phpfreaks.com/topic/154245-help-me-understand-why-mvc-is-beneficial/#findComment-811030 Share on other sites More sharing options...
keeB Posted April 16, 2009 Share Posted April 16, 2009 Yes. Small projects grow to large projects without rhyme or reason. Writing tag soup PHP pages makes maintenance a nightmare, while writing a proper model has little overhead. There's *zero* reason to not implement a design pattern like MVC. Unless of course you're not writing a website. Quote Link to comment https://forums.phpfreaks.com/topic/154245-help-me-understand-why-mvc-is-beneficial/#findComment-811179 Share on other sites More sharing options...
ambertch Posted May 15, 2009 Share Posted May 15, 2009 Yes. Small projects grow to large projects without rhyme or reason. Writing tag soup PHP pages makes maintenance a nightmare, while writing a proper model has little overhead. There's *zero* reason to not implement a design pattern like MVC. Unless of course you're not writing a website. Do you happen to have a link somewhere with examples of functionalities/things which should be part of the m, v, c? Like for example displaying a sortable table. I could definitely say the CSS and non-table html is part of the view... the controller has the db abstraction layer? And what about the php that generates the html for the table? The table's a view, but content should be generated by the model. Yeah, I'm confused Quote Link to comment https://forums.phpfreaks.com/topic/154245-help-me-understand-why-mvc-is-beneficial/#findComment-834470 Share on other sites More sharing options...
GarrettW Posted May 15, 2009 Share Posted May 15, 2009 ambertch, here's my understanding of it, as it pertains to your sortable-table scenario. The Controller is where the "business logic" takes place ... i.e. all the computation and processing. The core of the application, you could say. The DB abstraction layer is NOT in the Controller - it is in the Model. the Model is the link between a Controller and the raw data. You are correct that the HTML & CSS are part of the View, but the PHP that generates the HTML is also part of the View. The View takes the Controller's output and formats it for display. someone please correct me if i'm wrong, as I'm just learning this stuff too. Quote Link to comment https://forums.phpfreaks.com/topic/154245-help-me-understand-why-mvc-is-beneficial/#findComment-834650 Share on other sites More sharing options...
nadeemshafi9 Posted May 15, 2009 Share Posted May 15, 2009 Theoretically you could take any part of MVC and put something else in its place without changing other parts. It's easiest to imagine when we consider View. You could have one View that generates fancy, colourful, CSS styled HTML Web pages for traditional browsers, and another that generates plain Web pages for mobile devices with low bandwidth. Both would be using same Models and same Controllers. You don't have to introduce any changes into Models or Controllers if you want to switch the view. You can also easily add another view for generating RSS, then another for.. .something else... On the Model side one could easily imagine the need to switch from MySQL to Oracle to PostgreSQL... With MVC pattern switching a database engine should not require any changes to Controllers or Views. i like the browser small device example it woudl pan out like this http://domain/acontroler-eg-houses/a-method-that-outs-a-view-using-a-controler-method-inside-wich-there-is-model-interactivity-FOR-BROWSER/somvarname/varval http://domain/acontroler-eg-houses/a-method-that-outs-a-view-using-a-controler-method-inside-wich-there-is-model-interactivity-FOR-MOB/somvarname/varval http://domain/acontroler-eg-person/a-method-that-outs-a-view-using-a-controler-method-inside-wich-there-is-model-interactivity-FOR-BROWSER/somvarname/varval http://domain/acontroler-eg-person/a-method-that-outs-a-view-using-a-controler-method-inside-wich-there-is-model-interactivity-FOR-MOB/somvarname/varval http://domain/acontroler-eg-person/another-method-that-outs-a-view-using-a-controler-method-inside-wich-there-is-model-interactivity-FOR-BROWSER/somvarname/varval http://domain/acontroler-eg-person/another-method-that-outs-a-view-using-a-controler-method-inside-wich-there-is-model-interactivity-FOR-MOB/somvarname/varval when you use these its apparent how much better it is, you can move functiuonality about easily everything is encapsulated and ajax becomes much more simple using this format of url pluss its google friendly extjs Ext.Ajax.request({ url: '/person/getname/id/1', success: someFn, failure: otherFn, headers: { 'my-header': 'foo' }, params: { foo: 'bar' } }); Ext.Ajax.request({ url: '/person/getaddress/id/1', success: someFn, failure: otherFn, headers: { 'my-header': 'foo' }, params: { foo: 'bar' } }); i use the zend_framework it comes fully strapped with functionaly directory structure classes and a bootstrap file mod rewrite app.ini to controle configuration complete rewrite of all php constructs http://framework.zend.com/manual/en/ Quote Link to comment https://forums.phpfreaks.com/topic/154245-help-me-understand-why-mvc-is-beneficial/#findComment-834666 Share on other sites More sharing options...
spaze Posted June 19, 2009 Share Posted June 19, 2009 I created my own blog with ZF (http://www.majgaj.com/blog) and when I finished my project I realized I was missing the RSS feeds function. Since I had View and Models set, all I had to do was create rssAction() function into my controller and create new View for the actual RSS feed. All in all this RSS addition took me five minutes. If I would like to make a lighter layout for, say, mobile device, it would also take me five minutes to accomplish this. This is why I really like MVC design pattern. Quote Link to comment https://forums.phpfreaks.com/topic/154245-help-me-understand-why-mvc-is-beneficial/#findComment-859479 Share on other sites More sharing options...
phpFirstJoy Posted June 29, 2009 Share Posted June 29, 2009 I'm exploring the Kohana PHP framework, and I can see how views, controllers, and the template work together, but I haven't had time to figure out the use of models. I'm used to procedural PHP, and while I understand and use OOP, MVC of Kohana takes me to a new level of feeling stupid. I really don't understand the need for MVC at all. Slightly off-topic... My 2 cents: you can also use MVCL (L for language) which can possibly, in the future, assist you in translating sites into different languages without hassle. Quote Link to comment https://forums.phpfreaks.com/topic/154245-help-me-understand-why-mvc-is-beneficial/#findComment-865288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.