SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Boston
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CMS/MVC/OOP questions on outline

    I have edited class names to clear confusion.

    I am building a personal CMS and believe that I am incorporating MVC to help design it. I am working on the front-end using HarryF's MySQL class along with Brian Lozier's template class. The template class, templates (VIEW) and the classes below (MODEL) will be brought together by the actual PHP pages (CONTROLLER) served to the user. Regarding MVC, I think this is correct; if not, I enjoy thinking about it like this and it makes much sense. Is this correct? I would hate to think that I actually understand something .

    Also, obviously the classes below are a rough outline, but do they make sense? I don't want to create a superclass or one with methods that don't belong if there's a better way to code it. I would like to realize the benefits of OOP, or at least learn them. So, after much reading, this is what I have come up with so far:


    PHP Code:
    class Article {
        var 
    $db;
        var 
    $arg;
        
        function 
    Article(& $db,$arg=false) {
        }
        
        function 
    GetArticle() {
        }
        
        function 
    GetAuthor() 
        }

    PHP Code:
    class Topic {
        var 
    $db;
        var 
    $arg;
        
        function 
    Topic(& $db,$arg=false) {
        }
        
        function 
    GetTopic() {
        }
        
        function 
    GetTopicList() {
        }

    PHP Code:
    class Profile {
        var 
    $db;
        var 
    $arg;
        
        function 
    Profile (& $db,$arg=false) {
        }
        
        function 
    GetProfile() {
        }
        
        function 
    GetAuthorArticles() {
        }

    Am I missing a pattern with these classes? I can't think of how or why I would want to extend one of these, they are simple in that all they do is retrieve data from the database to feed to the templates.

    I would appreciate anyone's suggestions/opinions. You guys have always been great, thank you!
    Last edited by Lewis; Sep 2, 2004 at 07:38.
    -Lewis

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As a blanket statement, I would say you should never pass a $db anything to a View component. Wrong layer. Db access belongs only in model classes, the way that HTML belongs only in View classes.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Boston
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    As a blanket statement, I would say you should never pass a $db anything to a View component. Wrong layer. Db access belongs only in model classes, the way that HTML belongs only in View classes.
    I should've made that more clear, poor naming on my part. The class structures above are model classes. They have "view" in their name to better describe what information they fetch.
    -Lewis

  4. #4
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yer, I noticed the database aware variable myself, and I tell you, and had a sudden urge to take a dump, just out of fright I think

    But if those class(es) are representing a Model, then they look decent enough to me.

  5. #5
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Lewis
    I should've made that more clear, poor naming on my part. The class structures above are model classes. They have "view" in their name to better describe what information they fetch.
    I guess that would be the pot calling the kettle black then. I have "View" classes that I have come to concieve of as belonging to the Controller becuase the broker information between the Models and the template engine (View)

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Boston
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for working with the skeleton structure that I provided. I would code more, but I use voice recognition as I don't have the use of my hands. Long story short, it can get very tedious and I tend to plan, plan, plan...
    Quote Originally Posted by sweatje
    I guess that would be the pot calling the kettle black then. I have "View" classes that I have come to concieve of as belonging to the Controller becuase the broker information between the Models and the template engine (View)
    It is a bit confusing because right now all the classes do is retrieve information from the database for the templates. Since posting this, I have decided that I'll also use these classes for the backend (I'm just using phpMyAdmin for now) and include methods for insert and update. I think that makes sense.

    Quote Originally Posted by Widow Maker
    Yer, I noticed the database aware variable myself, and I tell you, and had a sudden urge to take a dump, just out of fright I think

    But if those class(es) are representing a Model, then they look decent enough to me.
    I'm a bit confused on why you don't like the database variable?

    Also, are there any core patterns that I'm missing that I should take advantage? I have considered using the DAO pattern to further separate things but I'm not sure I need that level of complexity in the CMS. I'm not going to be using another kind of database, but it is possible that the database structure will change.

    I'm not trying to make things more complex, I just want to take full advantage of OOP in PHP.
    -Lewis

  7. #7
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Currently I do not use a DAO as my applications are not all that large or complex (for the moment) though as Marcus has said in one post or another, use a DAO if you have a lot of code generatable scripts.

    Ie To save you a lot of time and effort, code generate your DAO classes instead of typing the script for every class

    Ideally, this is more suitable to larger projects, etc as I see it ?

    As to my earlier post, this was in regards to the naming of your posted scripts, ie *Views whereby the database object is in the wrong layer, as Jason suggested

    Now though, you've cleared that point up and declared them as Model(s) so no problems there, design or layer wise


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
  •