Jump to content

Recommended Posts

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.

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.

 

 

 

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.

  • 4 weeks later...

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  >:(

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.

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/

 

  • 1 month later...

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.

  • 2 weeks later...

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.

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.