Jump to content

How use to MVC


Polymorf

Recommended Posts

hello!

I find this tutorial on the MVC he looks very interesting but I can not get too used to someone could help me?

http://www.phpro.org/tutorials/Model-View-Controller-MVC.html#6

 

example:

 

I would like to import a model that uses the database with PDP!

 

and I do not know how or I can use the header (Location: ...)

 

I started in OOP

 

thank you for your help !

Link to comment
Share on other sites

  • 2 weeks later...

hello!

I find this tutorial on the MVC he looks very interesting but I can not get too used to someone could help me?

http://www.phpro.org/tutorials/Model-View-Controller-MVC.html#6

 

example:

 

I would like to import a model that uses the database with PDO!

 

and I do not know how or I can use the header (Location: ...)

 

I started in OOP

 

thank you for your help !

Link to comment
Share on other sites

I thin you mean "How to use MVC"

MVC is just one (of many) framework patterns.  So far out of all of the patterns I have used I like

MVC the most.  The general idea is very basic.  There are 3 types of logic.  The Model, the View, and the Controller.  The Model is where anything related to SQl/platform specific SQL or anything related to database work.  This is where your queries will go.  Generally you have 1 model for each database table and those models will have configuration options to help you use that model better.  Then the Controller is what does all of your "work" and gathering your data and co-ordinating with the Models and gathering everything together. Then finally the View.  The Controller takes all of that data and inserts it into the "view" which simply shows that data on the screen and then formats it appropriately (Xhtml/Css would be in the view).

Link to comment
Share on other sites

 

ok thank you!

 

I understand the principle now!

 

the tutorial that I found is good, but Kevin Waterson who have the author does not give an example with the class db!

 

the link is : http://www.phpro.org/tutorials/Model-View-Controller-MVC.html

 

he put a static instance of a global script init.php

but I do not know how to retrieve the body from one of my classes model!

 

he said the matter as follows in the file init.php

$registry = new registry;

$registry-> db = db:: getInstance ();

 

Now how do I recover the body in a class model that I have?

 

because I tried that and it does not work!

 

in one method:

 

public function getMessage()
{
       // an exemple for my model

       $request = "SELECT * FROM messages";
       $pdo = $registry->query($request);
       return $pdo->fetch(PDO::FETCH_OBJ);
       
}

 

 

I say that I repeat my class PDO but what keeps the singleton pattern and to review always a getInstance

 

 

I apologize if my English is not good! I use google translate to help me!

 

thank you fro your help ^^

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.