Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts

    Question about the basics of MVC

    I'm going to start learning MVC using CakePHP and I'm trying to get a basic understanding before I jump in.

    If I was building a simple page what displays a form, then on submit stores the data in a database, would the structure be

    View -> Displays the form
    Model -> Processes and stores the data in the database
    Controller -> Calls the function in the model to process the data

    Or would the process/storing be done in the controller and the model do something else?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Although I don't do PHP MVC (since the concept *really* doesn't make a lot of sense for a template language), the last time I did so in java I designed a passive many to many MVC which I used crud for the dataaccess level. So I linked it in through the controller in order to initiate any commands required. The models are literally just the data keepers and haven't a clue about any other functionality (including the controllers). I wrote property changers and chained them to reflection so that when a command is issued on the controller it was responsible for telling the model to alter its values, and the models were given listeners to detect changes in their property states from the controllers.
    This approach seemed brilliant when I wrote it; neither the view nor the model had any idea about a controller nor each other, but that sure did create a headache with the collection levels while still adhering to the overall concept of the MVC I wrote. What a mess, I can't even remember what I did to get around it; pretty sure I had to give on something.

    Ultimately though, it doesn't really matter which it goes in. Just don't put it in the view.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    tomharto (04-18-2013)

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Ahh okay, thanks .

    The main reason I'm learning MVC is I'd like to get a job doing web development and anything I can put on my CV will be a bonus, and a few jobs I've looked at say knowledge of MVC is a benefit.


  •  

    Posting Permissions

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