Jump to content

Archived

This topic is now archived and is closed to further replies.

Polymorf

How use to MVC

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 !

Share this post


Link to post
Share on other sites

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 !

Share this post


Link to post
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).

Share this post


Link to post
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 ^^

 

Share this post


Link to post
Share on other sites

×
×
  • 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.