SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Where to place my class for DB Query?

    Hi,

    I am working on a very simple custom CMS based on Model/View/Controller. I am doing it so I can learn more about PHP and this will force me. My system is not perfect and my question is not whether it has right structure or not.

    But its one specific question. Following is my structure
    - index.php
    -- application
    ---- views/index.php
    ---- controller/index.php
    ---- model/index.php

    -- package
    ---- RSS
    ------ Get RSS from external site and store in database (run using cron)



    Now, I need to show 5 latest RSS feeds in index.php. Should I create a model/rss.php? Or should I create a RSSDB class in package (package/rss/rssdb.php) which can grab those entries?

    I may or may not have an RSS Model/View/Controller in future. And it may or may not have to do with same tables. Although, if that happens then does it mean I keep using rssdb.php?

    As you can see, I am quite confused. Can you please help?

    Thanks
    ---------------------------
    Errors = Improved Programming.
    My Site

  2. #2
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your motive of making package is to keep things independent (almost like plugin) then may be one idea can be to have
    model,view and controller with in that package folder or may be inside rss folder and put database access in model of that making a page...

    that is how ,many standard scripts do...

  3. #3
    Non-Member
    Join Date
    Oct 2007
    Posts
    363
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    There's not really a set rule, but I generally keep models for things that are going to be persisted (ie stored in the database), and then create what I call "service" classes for doing things like this, so I'd probably split it out into a service class that is able to read from your rss feed, and then create a separate model if you actually want to store the data anywhere. That way you've got a nice clean interface for reading the rss, and another separate one for persisting it if you need to do that.

    So I guess my answer would be to do both - keep the model/rss.php just for saving the data to the database, and have the service/package class do the work involved in actually reading the rss feed and grabbing the data.

    (Also, I'm fairly sure what I'm referring to as a service is the same as what you're referring to as a package).


Bookmarks

Posting Permissions

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