Zend Framework Forum

Go Back   Zend Framework Forum > Zend Framework General discussions > General Q&A on Zend Framework

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-08-2010, 05:02 PM
Junior Member
 
Join Date: Feb 2010
Posts: 1
Default How to use Models properly?

I see Controllers as a place where I can receive HTTP Requests and Views as a means to return XHTML/XML/JSON, etc, but I have yet to get my head around Models. From any MVC best practice guides I've read (and there has been many), it seems people are pushing a lot of their code in to Models.

The majority of web applications will use databases for persisting data beyond sessions, yet all of the example code I've seen from tutorials online is extremely basic in that you end up mapping an object directly to a single table. A lot of my select queries would typically return a ResultSet that comprises of data from multiple tables, and includes things like specific MySQL functions, etc. I know it's not the most portable approach, but I don't have a need to move database vendors. This idea of mapping an object to a single table and just running queries on that appears fantastic, but I can't see how it would be of any use beyond the most basic of database designs and applications.

In any one application the sheer number of select queries alone that I could run against a database could span hundreds of unique query types. Would it mean that I would need to create a Model that represents the results from each those queries that I need (which seems like an awful lot of code, just to be able to have an object oriented view of DB interaction).

However I think that my understanding of Models and how I can use them to interact with databases using the Zend Framework is way off the mark, and I beg someone to please help me understand how this works.

I would consider myself a reasonably proficient programmer and have been using PHP for a few years, but I have still to get my head around MVC and Zend. I am tired of re-inventing the wheel and would love to take advantage of the solid foundations that the Zend Framework provides for my current/future apps.

any help appreciated
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-08-2010, 09:49 PM
Member
 
Join Date: Feb 2009
Location: Poland
Posts: 83
Default

How you implement your models is totally up to you. They don't have to extend Zend's Db classes. If you wish, you may put and execute raw string queries using mysqli or use ORM like Doctrine. Whatever suits you best.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-09-2010, 08:47 AM
SirAdrian's Avatar
Member
 
Join Date: Apr 2008
Posts: 83
Default

For common database-related models, I write new classes that use Zend_Db_Adapter_* and Zend_Db_Select. I've also used Doctrine a few times for models. Some models don't even use database connectivity... it's really up to you.

A model is an abstract thing, so there are no built in classes for it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT. The time now is 07:38 PM.


Designed by: Miner Skinz Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0