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

SitePoint PHP Blog:
MVC - a Problem or a Solution?
July 28, 2014 @ 11:42:36

The SitePoint PHP blog has a new post by Jeroen Meeus that wonders if MVC is a solution or a problem when it comes to developing web applications.

Repositories, Adapters, MVC with all it cousins, SOLID, RTFM… As a (PHP) developer, those words are thrown at you from every corner of the web. And I hate it, I've had enough. Stop telling me what to do and show me those kittens instead. [...] When solving the web-application problem, we are forced to use MVC. The dev community often frowns upon those who don't use it, but seldom lets those they're frowning upon ask why. [...] MVC doesn't solve the Code complexity problem. It doesn't solve the code reuse or no-flexibility problem either. And it doesn't guarantee decoupled code.

He goes on to talk about how design patterns don't "solve problems". Rather they help us as developers by providing a best practice we can follow to get the job done. He suggests, though, that MVC has become "the new Singleton" but it has been used so much in so many different ways, it's boarding on the point of being abused.

Depending on the situation, and the problem at hand, different patterns can help you write robust, secure and understandable code. Just be careful using them - if you catch yourself using the MVC pattern for a 1-pager, ctrl+a del.
0 comments voice your opinion now!
mvc designpattern problem solution abuse

Link: http://www.sitepoint.com/mvc-problem-solution/

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

Rami Alnawas:
How to unit test code with Phalcon MVC Models
April 29, 2014 @ 11:57:39

Rami Alnawas has posted an interesting tutorial for the Phalcon users out there showing one way you can unit test your models. It's based on his own experience with the framework in a current project.

My first contribution to the PHP community in general, and Phalcon folks in particular, was the introduction of MVC Functional Testing with PHPUnit, this meant that Applications developed using Phalcon Framework could be unit tested by requesting a url then asserting that the response is handled by a specific action within the controller. [...] To date, my latest addition is an example of how to unit test code that utilises Phalcon models, mainly the various static find methods. The code is available on github and the coverage report is coveralls.io.

He shows it at work, creating a simple "Popup" model and a facade to help with making instances for testing. He also includes the code to test this facade, checking the results of methods like "fetchall", "select" and "execute".

0 comments voice your opinion now!
phalcon framework unit test coverage mvc model tutorial

Link: http://www.rami.me.uk/how-to-unit-test-code-with-phalcon-mvc-models

Reddit.com:
Any ideas on what "MVC agnostic" PHP code is?
February 06, 2014 @ 10:43:59

On Reddit.com there's a recent post that asks for a bit of clarification about the term "MVC agnostic" as said by a potential employer:

A potential employer wanted to see some of my code before an interview. They originally asked for MVC or OO PHP that I'd written in the last 30 days - fair enough. [...] They've come back to me (via the recruitment agent) asking for some "MVC agnostic code" as no one on staff has worked with codeignitor before. Any ideas what they mean by this as I'm slightly stumped.

Most of the responses to the post suggest something that's becoming more and more of a trend in PHP development lately - framework agnostic development. Basically, this is creating functionality (usually in packages) that can be dropped into any application and used independently.

Other comments suggest other possible definitions like:

  • "This is the first time that I have heard someone mention "MVC agnostic" and on the face of it I would question their own understanding of the phrase."
  • "Yeah, the key bit in your question there was 'via a recruitment agency'. Half of the time, they haven't got a clue about the industry and so jargon gets tossed about something awful."
  • "I think it's more accurate to say that what they want to know is that you actually know PHP, and not merely a set of tools on top of PHP that make you productive in the way you prefer."
0 comments voice your opinion now!
mvc agnostic framework opinion package development example

Link: http://www.reddit.com/r/PHP/comments/1x2xea/any_ideas_on_what_mvc_agnostic_php_code_is/

Paul Jones:
"Page Script" As A Degenerate Controller
February 04, 2014 @ 12:26:52

In his latest post Paul Jones looks at the more legacy structure of "page controllers" (a site based on several pages rather than an MVC style) that was common before the "MVC revolution" in the PHP community years back.

Almost all of the legacy applications I've had to deal with were page-based. In doing the work to modernize them, there comes a time where the page script has been refactored to look very much like a page controller, with some distinct but not critical differences. As such, I have come to consider the typical PHP page script to be a degenerate form of a page controller. With a little imagination, I think it's easy to see why.

He talks about how, in this older situation, the web server becomes a sort of "simplified front controller+router+dispatcher" and the PHP page acts as a "controller". He suggests that, even though this structure isn't as well separated as an MVC application, it can still be organized to make it easier to maintain.

0 comments voice your opinion now!
page controller mvc legacy structure

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

Zend:
Apigility Progress report zf-mvc-auth, packagist, and PHP's built-in web server
November 01, 2013 @ 15:52:11

In a new post to the Apigility forums today Matthew Weier O'Phinney has announced the release of an authentication/authorization component for the recently announced project from Zend. Apigility is a Zend Framework-based tool for easily constructing and managing an API.

We've been working hard on Apigility since ZendCon, and have released some more code into the wild. zf-mvc-auth exists to provide both authentication and authorization for your APIs; in fact, it's a bit of a general-purpose library for ZF2 MVC apps! Right now, we support HTTP basic and digest authentication out of the box, and will be working next on OAuth support. Authorization is done by default via ZendPermissionsAcl, as we discovered a problem with using RBAC: RBAC is deny-by-default, which does not work when you want an open-by-default schema. You may opt-in to deny-by-default, as well as mark individual services as requiring permission by default. Finally, you have the option of denying/allowing per HTTP method of a service as well.

You can find out more details about this functionality in this quick screencast. The zf-apgility module depends on this new zf-mvc-auth module, so it will be included and available by default in your APIs. In that same post Matthew also talks about the listing of the Apigility packages on Packagist service and a note for those wanting to use the built-in HTTP server to run the tool (a PHP version dependency).

0 comments voice your opinion now!
apigility progress zendframework mvc authentication authorization packagist http server

Link: https://groups.google.com/a/zend.com/forum/#!topic/apigility-users/_mOPkxxmGYI

Ben Youngblood:
MVC Is Not Enough
September 04, 2013 @ 09:12:25

Ben Youngblood has a new post to his site suggesting that MVC is not enough to build good, robust applications (PHP or not) just because a good portion of the frameworks implement it.

With few exceptions, any software engineer worth his/her salt have at least heard of the model-view-controller pattern. It's been around since it was introduced to Smalltalk in the late 1970s and has been a staple pattern in object-oriented languages for as many years. Nearly all the leading PHP frameworks include some form of MVC implementation. With so many frameworks and developers espousing its use, you would think it's the best pattern for building your application. And you would be wrong.

He's not suggesting abandoning MVC altogether for something else. He just wants a reexamination of how it's being used and how to improve the structure of the applications using it. One option is to adhere more to the SOLID principles, avoiding things like domain logic in controllers and "fat" models with too much logic.

Chiefly, MVC is one part of your application, not your application. If you find that you are building your domain logic inside models, views, or controllers, then you are abusing MVC. No substantive application can, or should, be made to fit inside MVC.
0 comments voice your opinion now!
mvc opinion solid principles improvement

Link: http://blog.bjyoungblood.com/2013/08/21/mvc-is-not-enough

PHPMaster.com:
Aura.Web Aura's Page Controller for MVC
June 05, 2013 @ 09:58:42

On PHPMaster.com today Hari K T has spotlighted one of the components from the Aura framework, the Aura.Web component.

MVC is an acronym that means Model-View-Controller. In this tutorial I would like to introduce you to Aura.Web, the controller component of the Aura Library. Here I'll show you how to use it to build your own controller, and also how to use a response transfer object to issue HTTP response headers, and integrate a templating engine like Mustache for rendering views.

He starts off with an overview of how the component is architected and how it is used to create controllers and what dependencies it needs injected. He talks about some of the objects and the methods they provide and includes some sample code for a basic "Index" controller. He shows how to integrate the Mustache templating engine for output and how to work directly with HTTP responses.

0 comments voice your opinion now!
auraweb aura framework page controller mvc tutorial introduction

Link: http://phpmaster.com/aura-web-auras-page-controller-for-mvc

Happy Accidents:
Orno Skinny Series Part 1 Building a RESTful API
March 19, 2013 @ 11:36:54

On the Happy Accidents site there's a new post talking about building a RESTful API (part one of the series) using the Orno dependency injection and MVC components.

have recently been writing a collection of PHP components exploring different design patterns for building applications. With the MVC layer close to completion I decided to write a couple of guides on how these components could be wired together to achieve several different application formats. First in this series will highlight the power of OrnoDi when used to resolve your objects, to do this we will be building a simple RESTful api with the minimal amount of configuration and bootstrap code.

He includes instructions to install the components (via Composer) and configure the DI container with the needed settings. He shows examples of the autoloading setup, how to handle the routing and how to create the sample model and controller to respond to the sample REST requests.

0 comments voice your opinion now!
rest api orno component mvc dependencyinjection tutorial



Community Events





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


developer conference framework interview introduction api deployment list series laravel development threedevsandamaybe release language code application tips zendserver podcast community

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