TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
View Poll Results: How are you with MVC in PHP?
I am using framework which are in MVC 12 63.16%
I do all my applications in MVC which is of my own 3 15.79%
I never use MVC. 3 15.79%
My applications are efficient without MVC 2 10.53%
Multiple Choice Poll. Voters: 19. You may not vote on this poll

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-22-2009, 04:23 AM   #1 (permalink)
The Visitor
 
Join Date: Nov 2009
Posts: 4
Thanks: 0
icosytech is on a distinguished road
Default MVC approach in PHP Development

MVC - Model View and Controller. The most standard approach in application development is MVC according to many peoples consideration. What if it would be implemented in PHP?

Most of the framework in PHP using MVC, then how about the use of MVC in our custom applications?

Lets put up words right here, to get through the sane...

icosytech is offline  
Reply With Quote
Old 11-22-2009, 10:33 AM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Personally I like the Model Plane > View from my Patio > BBQ pattern.
delayedinsanity is offline  
Reply With Quote
Old 11-22-2009, 12:05 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
Personally I like the Model Plane > View from my Patio > BBQ pattern.
What is that?
__________________
Tanax is offline  
Reply With Quote
Old 11-22-2009, 05:51 PM   #4 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

delayedinsanity haha that sounds like a great model to follow
tony is offline  
Reply With Quote
Old 11-24-2009, 03:24 AM   #5 (permalink)
The Contributor
 
Join Date: Feb 2007
Posts: 64
Thanks: 9
Killswitch is on a distinguished road
Default

About a month ago I had never touched anything MVC. My first time looking at it it just seemed like it over complicated everything. I decided to take a closer look and write my own basic little framework and now I understand it very well and really like using it. It might not be appropriate for everything, escpecially very small scripts, but I can definitely see myself using it more from now on.
Killswitch is offline  
Reply With Quote
Old 11-24-2009, 03:36 AM   #6 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Using MVC to handle a form is like hitting up Wal-Mart in a Peterbilt.

If you're developing a major application however (delivering the goods to Wally World), then MVC is completely the opposite of over-complication. It's a very solid design pattern, usually being built through the use of other very popular design patterns, which I would presume accounts for a large portion of its popularity.

At the very least, if you plan on developing enterprise level applications, or even just programming (PHP or otherwise) for an extended period of time, it's one of the many patterns that should be learned just to gain the experience from it. The concept alone can turn some on-paper ideas from improbable to highly possible very quickly.

I still prefer BBQing though.
delayedinsanity is offline  
Reply With Quote
Old 11-27-2009, 07:42 AM   #7 (permalink)
The Wanderer
 
adham is me's Avatar
 
Join Date: May 2009
Posts: 19
Thanks: 4
adham is me is on a distinguished road
Default

i use codeIgniter and really it simplifies all work incredibly !
__________________
I love you NASSER
adham is me is offline  
Reply With Quote
Old 11-27-2009, 09:19 AM   #8 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

MVC is great when used in the appropriate places. It can and will over complicate things if the problem has a relatively simple solution, akin to hammering a panel pin in with a sledgehammer, whilst it will probably do the job its completely unnecessary, when a smaller hammer would do it just fine (and will also minimize the risk of pulverizing the object in which the nail is going into)

I have found MVC to be fabulous in my work on a daily basis on medium to large projects.

I must say, I too prefer to BBQ, grr now i'm hungry again!
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 11-27-2009 at 09:19 AM. Reason: speelink
sketchMedia is offline  
Reply With Quote
Old 12-10-2009, 02:47 AM   #9 (permalink)
The Wanderer
 
Join Date: Dec 2008
Posts: 16
Thanks: 2
ChrisR is on a distinguished road
Default

I have never used MVC as i have never got how it works.

also what this BBQ?
ChrisR is offline  
Reply With Quote
Old 12-10-2009, 03:29 AM   #10 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Basically it's like this:

- Different controllers (or methods in controller classes) represent different pages
- Controllers use models to interact with the database
- Controllers use views to display HTML to the user

It just divides your application into parts based on primary function. Makes it a lot more organized and speeds development.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 12-10-2009, 01:18 PM   #11 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by ETbyrne View Post
- Controllers use models to interact with the database
Not really. They don't need to use models to interact with the database. Otherwise you wouldn't be able to access the database from the controllers. Besides, models can be used for a number of other things, not only database handling.

However, models are most often used to interact with the database. It's just not limited to it.
__________________
Tanax is offline  
Reply With Quote
Old 12-10-2009, 04:48 PM   #12 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Otherwise you wouldn't be able to access the database from the controllers.
Now why would you need access to the DB via the controller?

In my mind controllers should not do any form of business logic, all of that is handled via the model, just like views handle presentation logic, so therefore you shouldn't need to access the DB via the controller. Obviously there is a need for a certain amount of logic in controllers, as there is in the view layer (don't get me started on PHP template languages at this stage of the day PLEASE), but to have the controller layer bunged up with logic is just silly, you may as well just go back to the old skool way and have a php file per page.

Models are not synonymous with database. I quite often see code that is supposedly 'MVC' and all I can see in the model is a pointless 'ActiveRecord' (or similar) class with no logic in it and a controller littered with business logic.

Controllers are there to glue the model to the view, interpreting user input into the model and passing data back to the user via the view.

fat model and a thin controller is all you need to remember.

I'll stop myself there as we are wandering dangerously close to the 'off topic' mark and I will being ranting before long.

Now where did I put my coffee?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 12-10-2009, 08:21 PM   #13 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by sketchMedia View Post
Now why would you need access to the DB via the controller?

Now where did I put my coffee?
You should probably have taken your coffee before replying xD
I didn't say you should access the database via the controller. I just said you CAN, and that the use of models isn't limited to database handling.

I "proved" this by saying that otherwise you wouldn't be able to access the database via the controller. Because if models would be limited to database handling, then you should be forced to use models for the database handling, and controllers wouldn't allow you to access the database. But controllers do allow this thus models aren't limited to database handling.
__________________
Tanax is offline  
Reply With Quote
Old 12-10-2009, 08:51 PM   #14 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

You both make valid points, but keep in mind I was just generalizing for the sake of simplicity. Also remember that there are different variations of MVC, but again, that just makes it all the more complicated for someone trying to learn it at first. :)
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 12-10-2009, 09:21 PM   #15 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
You should probably have taken your coffee before replying xD
I didn't say you should access the database via the controller. I just said you CAN, and that the use of models isn't limited to database handling.

I "proved" this by saying that otherwise you wouldn't be able to access the database via the controller. Because if models would be limited to database handling, then you should be forced to use models for the database handling, and controllers wouldn't allow you to access the database. But controllers do allow this thus models aren't limited to database handling.
Yea, its not a good idea me replying to threads after just comming out of a meeting and a lack of coffee, I'll remember that in the future! I still maintain that the idea of accessing the DB from the controller makes me feel a little edgy, it will end up in a crawling horror of an application!

Quote:
Originally Posted by ETByrne
You both make valid points, but keep in mind I was just generalizing for the sake of simplicity. Also remember that there are different variations of MVC, but again, that just makes it all the more complicated for someone trying to learn it at first. :)
Indeed! Its probably one of the hardest patterns to learn because it is interpreted by many people in many different ways. The way I do it is the way I found it most useful for my own projects, I found that lumping most of the logic in models made it alot easier for me in a number of ways (reuse, unit testing etc).
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 12-26-2009, 05:45 AM   #16 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 18
Thanks: 1
Jarod B is on a distinguished road
Default

I dont even know what MVC stands for haha.
Jarod B is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get PHP 5. to work? Newbie windows PHP guy DotNetTim Absolute Beginners 11 02-01-2013 11:02 AM
Hi to PHPDev, Let us ameliorate PHP development. icosytech Member Introductions 1 11-21-2009 04:25 PM
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM
what are all the subjects in php? sarmenhb General 7 01-21-2008 05:41 PM


All times are GMT. The time now is 04:00 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design