+ Reply to Thread
Results 1 to 3 of 3

Thread: How to use Models properly?

  1. #1
    phobos is offline 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

  2. #2
    maciek.231 is offline Member
    Join Date
    Feb 2009
    Location
    Poland
    Posts
    90

    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.

  3. #3
    SirAdrian's Avatar
    SirAdrian is offline Member
    Join Date
    Apr 2008
    Posts
    87

    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.

+ Reply to Thread

Similar Threads

  1. Zend_Oauth working properly?
    By xil3 in forum General Q&A on Zend Framework
    Replies: 0
    Last Post: 06-28-2010, 10:46 PM
  2. Bootstrap file not working properly.
    By darrenl in forum Installation & Configuration
    Replies: 1
    Last Post: 05-07-2010, 08:14 PM
  3. How to properly use Zend_Test and Zend_AMF
    By shinank in forum Core Infrastructure
    Replies: 0
    Last Post: 01-29-2010, 12:58 PM
  4. routing doesn't work properly
    By jsanders in forum Model-View-Controller (MVC)
    Replies: 3
    Last Post: 03-27-2008, 11:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts