SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2007
    0 Post(s)
    0 Thread(s)

    MVC - need help on example

    Well, i'm trying to learn MVC, but it's just confusing (and i'm a bit new to OOP aswell), especially the model and controller parts.

    So i was thinking that maybe the best way would be if i put most simple example i can think of, and will update this thread with how i think i would make application using this MVC, and you then tell me what i done wrong and how to correct it, if possible.

    So, i imagen you you would have this place where you can 'load' or how to say, movies. After some time, you give it back.

    So, you have two important enteties, movies and users.
    So you have database with these tables:

    - userID
    - first_name
    - last_name
    - location

    - movieID
    - title
    - year
    - description
    - available

    now, you would have simple website where you could simply check list of all users, check which movies are free to borrow, etc.

    now, file structure would be simple,
    - /models <--for model classes and such
    - /views <--to do anything with views

    so, i'll start with model, and this is where i wil need help.
    Now, i would have to class files, that would represent MODEL:

    file /model/userClass.php
    Class User
    - var first_name;
    - var var_last_name;
    - var userID
    - var location
    - function setNewUser(all needed data)
    - function returnUserByID(userID)
    - function listAllUsers() <-- would return array with all users
    file /model/movieClass.php
    Class Movie
    - var name
    - var description
    - var year
    - function setNewMovie()
    - function removeMovie()
    - function setFree() - tells that nobody is borowed movie right now so we can borow it
    - ....
    Am i right when i have set my model like this?
    now what about database connection?
    should i create new class that handles database connection, and then when definding instance of class, i pass the instance of this database class handle to the to this user or database class, if i need to bring user info from database?
    Or is it done some other way?

    I'll be going to write farther about this simple app, when i see i'm right about this (especially the databse connection problem).

    Sorry for troubles, and tnx for help!

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2008
    0 Post(s)
    0 Thread(s)
    Probably the easiest way to learn MVC is to play with an existing framework such as CakePHP or Codeigniter. There are many more you can try too, do a simple search. CakePHP and CI have pretty good user guides.

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2007
    0 Post(s)
    0 Thread(s)
    yeah i tryed some of them a bit, like zend framework, the only problem is that those usualyl implement all sorts of design patterns (like singletone pattern), so noob like me quicky gets confused by all that.



Posting Permissions

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