News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Reddit.com:
What exactly is 'model' in MVC?
June 20, 2014 @ 11:25:48

If you're relatively new to the world of the MVC (Model-View-Controller) design pattern and its use, you may be trying to figure out exactly what each piece is. One of the more difficult relationships is between models and controllers, more specifically what each are supposed to contain. In this discussion over on Reddit several people weigh in on their opinions and own suggestions about what models should be.

Sometimes I feel I should avoid session in model ... but sometimes I feel using session in controller is putting business logic in controller which is bad ... sometimes I feel I should avoid $_POST and $_GET in model ... but sometimes I feel receiving data in controller and then send all of them to model is an unnecessary move ... sometimes I feel one model should represent almost everything about one certain table ... sometimes I feel it's almost god pattern if that table is the core of your application, but separate the model into many model is confusing too since they are using the same table. I wanna be a Model Master who can explain 'Model' very well. Who can help me plz.

Comments on the post explain models in several different ways including:

  • Thinking of it as a representation of "domain" functionality
  • Models as a 1-to-1 relationship with database tables
  • The differences between them and collections
  • Links to some helpful libraries like Eloquent and Doctrine
0 comments voice your opinion now!
model mvc modelviewcontroller opinion definition

Link: http://www.reddit.com/r/PHP/comments/28luto/what_exactly_is_model_in_mvc/

Paul Jones:
Action-Domain-Response A Tentative MVC Refinement
May 07, 2014 @ 09:49:36

In his latest post Paul Jones has proposed a "tentative MVC refinement" as the structure behind your application. He suggests something called the action-domain-response pattern, focusing on some of the more common practices in web application development today instead of an ideal.

The term MVC has experienced some semantic diffusion from its original meaning, especially in a web context. Because of this diffusion, the Action-Domain-Response pattern description is intended as a web-specific refinement of the MVC pattern. I think ADR more closely fits what we actually do in web development on a daily basis. [...] We generally route and dispatch not to a controller class per se, but to a particular action method within a controller class. It is also partly revealed by the fact that we commonly think of the template as the View, when in a web context it may be more accurate to say that the HTTP response is the View. As such, I think ADR may represent a better separation of concerns than MVC does in a web context.

He goes through the structure he's worked up, showing the interaction between the parts and compares the flow to a typical MVC-based application. He also mentions a few other MVC pattern alternatives including Data-Context-Interaction and Model-View-ViewModel. He then gets into an actual code-based example using a typical blog application. He compares the directory structure and proposes that instead of one controller per file it becomes one action per file (and one response per file accordingly).

0 comments voice your opinion now!
modelviewcontroller mvc actiondomainresponse adr designpattern application

Link: http://paul-m-jones.com/archives/5970

NETTUTS.com:
MVC for Noobs
March 25, 2010 @ 10:05:34

If you're relatively new to the framework world and haven't quite gotten your head around the whole Model/View/Controller way of doing things, you should check out this new tutorial from NETTUTS.com giving an overview of the method that's so popular among PHP frameworks these days.

Model-View-Controller (MVC) is probably one of the most quoted patterns in the web programming world in recent years. Anyone currently working in anything related to web application development will have heard or read the acronym hundreds of times. Today, we''ll clarify what MVC means, and why it has become so popular.

The look at each part of the MVC stack including what it's for and how it connects with the other two parts. An example is included - not in code but with an image showing the communication between the modules. They wrap up the post with a look at why using a MVC framework can help you be more productive. Their example uses CakePHP but the ideas could be applied to any MVC framework out there.

0 comments voice your opinion now!
mvc modelviewcontroller tutorial introduction


DevShed:
Handling Views with CodeIgniter
March 19, 2009 @ 12:04:42

DevShed takes another look at the CodeIgniter framework with this first part of a new series tackling view handling in the lightweight framework. Views are the final stop for the processed data, displaying any one of a multitude of types of data back out to the waiting client software.

In reality, implementing this view-centric method is actually pretty easy to achieve. However, CodeIgniter provides web developers with enough flexibility to handle views in all sort of clever ways. Therefore, in this series of articles I'll be discussing in detail some common approaches that you can use to generate views, ranging from loading them sequentially, to using more complex methods, such as including views within other views.

They introduce you to the view system CodeIgniter offers and show you how to create a basic view as a part of a controller class that displays a page with a header, user content and a footer.

0 comments voice your opinion now!
view mvc modelviewcontroller codeigniter framework tutorial


Quinton Parker's Blog:
Smarty. Solving the wrong problem since 2001
February 06, 2009 @ 12:09:31

On the heels of some previous comments concerning the Smarty PHP templating engine, Quinton Parker has posted some of his own thoughts concerning the past and future of the tool.

Today's rant is about the Smarty templating system for PHP. A recent blog post by Paul M. Jones has rekindled my strong feelings against Smarty. Honestly its nothing personal. Its just I can't believe developers are still using Smarty or that they ever started using it. Unthinkable.

Quinton talks about when he first discovered patterns and N-tier including the Model-View-Controller pattern. This naturally lead to needing a templating engine for the views, but from everything he could tell about Smarty it "solved the wrong problem" (he chose phpsavant instead). He even points out an author who, despite writing a book on Smarty, still came back and said that there's no need to use something like that in an application.

4 comments voice your opinion now!
smarty template engine modelviewcontroller mvc phpsavant problem


Jani Hartikainen's Blog:
Food for thought utilizing models in MVC
December 08, 2008 @ 10:26:15

Jani Hartikainen has posted some food for thought to his blog today concerning models in a typical Model-View-Controller (MVC) setup.

"What is a model" and "Is Zend_Db_Table a model" seem to be asked once in a while on #zftalk. Frameworks say they have a full model available, thus they are MVC frameworks ORM libraries say they generate models. It seems the ActiveRecord pattern has become somewhat synonymous with model.

He points to a post from Padraic Brady on the subject and talks about how one might put it into practice. He admits to making a controller action just to get data from the database into a view, but offers a "more correct" alternative - a view helpers that creates a model instance your view scripts can use directly without the controller in between.

0 comments voice your opinion now!
mvc modelviewcontroller database access view helper instance


Padraic Brady's Blog:
The M in MVC Why Models are Misunderstood and Unappreciated
December 04, 2008 @ 11:19:36

In this new post to his blog Padraic Brady looks at why models are "misunderstood and unappreciated" in a Model/View/Controller sort of world.

By the time I'd finished both chapters [of my Zend Framework book] I realised I had spent a lot of space explaining the Model, most of it discussing how the Zend Framework does not actually give you one. In fact, no web application framework offers a complete Model (for reasons I'll explain later). However nearly all frameworks manage to avoid making that perfectly obvious. Instead they continually link the concept of a Model to the related, but not identical, concept of data access. This is quite misleading.

He looks at two things models are good for (maintaining state and enforcing rules on the data in the current state), how it seems most PHP developers perceive them, how controllers can be turned into "mutated models" and the idea that models should be classes and controllers are just processes (handlers for requests).

0 comments voice your opinion now!
modelviewcontroller mvc model underappreciated misunderstood controller


Eran Galperin's Blog:
The Advancing PHP Developer Part 5 Design Patterns
July 14, 2008 @ 09:32:26

As a part of his "Advancing PHP Developer" series, Eran Galperin has posted part five, a look at design patterns and what they can do for you and your application.

A design pattern is a general reusable solution to a recurring design problem in object-oriented systems. Design patterns are essentially blueprints that suggest how to solve a particular set of OO design problems while adhering to OO best good-practices (which I've recounted in my Object Oriented part of this series).

He talks about one of the most popular examples - the Model/View/Controller design pattern that is used in many rapid development frameworks for PHP (including CodeIgniter and the Zend Framework). He also briefly mentions a few others like the composite, singleton and decorator patterns.

Other parts of this series include looks at testing, refactoring and coding standards.

0 comments voice your opinion now!
designpattern mvc modelviewcontroller decorator composite singleton


Bill Karwin's Blog:
ActiveRecord does not suck
May 29, 2008 @ 17:07:50

Bill Karwin (formerly of Zend and the Zend Framework project) has a new post to his blog defending one of the more abused (both in code and in opinions) design patterns, ActiveRecord:

ActiveRecord is fine. It is a tool that does just what it's designed to do. What sucks is when developers try to make it do other things than what it's intended to do.

He cites his work with the Zend_Db component and how Mike Seth gets it right when he says that the pattern shouldn't be "ActiveRecord-View-Controller". He compares the ideas of a true Model in an MVC application with the incorrect ideas that many developers seem to hold.

A Model is a class that provides a logical component of your application domain. Models are products of OO design, which is a development activity I see get very little attention in the developer blogosphere or the developer tools market.

Models can reference one or many (or no) database tables and are not where the hard work is being done. That's saved for the ORM (or ActiveRecord) to do.

0 comments voice your opinion now!
activerecord designpattern modelviewcontroller mvc model orm


Michael Girouard's Blog:
Rolling Your Own MVC The View
April 28, 2008 @ 09:39:45

Michael is back with part three of his series stepping you through the creation of your own MVC framework (Part 1 and Part 2) with a look at the part that interfaces with the user - the View.

Using the view as a starting point may seem odd at first considering the view-related actions are some of the last steps in the page load scenario, but since our views don't have any external dependencies, unit tests are very easy to write and so is the accompanying code.

He explains how views work along with the rest of the framework and some of the basic rules surrounding how they get their data. Code comes along with the explanations for different views like XML, HTML and JSON methods of output.

0 comments voice your opinion now!
modelviewcontroller mvc view tutorial output xml html json



Community Events





Don't see your event here?
Let us know!


release language install library framework symfony opinion tips laravel list podcast update interview api community series introduction zendserver deployment package

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework