News Feed
Jobs Feed
Sections




News Archive
feed this:

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

CodeHeaps.com:
Creating a Blog Using Laravel 4 (Series)
February 18, 2014 @ 10:53:20

The CodeHeaps.com tutorial site, they've posted the latest in their tutorial series creating a blog with the popular Laravel framework. In the first part they looked at models and database seeing, in part two they focused on controllers and in this latest part they focus on routing.

In this article we will create a simple blog using Laravel 4. Our blog application will have the following features: display posts with read more links on home page, search posts on blog, display a single post with comments and allow users to post comments. Administrator will be able to perform CRUD operations on posts and comments [and ] will be able to moderate comments.

In the three parts so far they show some simple migrations to create the "posts" and "comments" table and some basic (lorem ipsum) content. They create a basic "blog" controller and login functionality to identify the current user. Finally, they create the routing to hook it all together including some "before" hooks and authentication protection on the administrative areas.

0 comments voice your opinion now!
series tutorial laravel framework blog beginner model controller routing

Link: http://www.codeheaps.com/php-programming/creating-a-blog-using-laravel-4-part-3-routing/

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

Kristopher Wilson:
Decoupling the Framework
December 02, 2013 @ 12:19:36

Kristopher Wilson has a new post to his site talking about something that could be very difficult with an existing application (and a good starting place for a new one) - decoupling from the framework. He advocates that your application shouldn't be an extension of the framework, more so a user of it to make it potentially easy to replace.

We spend a lot of time discussing and analyzing the features and merits of several frameworks, trying very hard to make sure we find the perfect one to use for our project. Rightfully so: picking the wrong framework can lead to a slew of issues down the road in terms of maintenance and scalability. [...] We also spent a considerable amount of effort making sure that there is minimal amount of coupling within our code. Strong coupling leads to problems testing, adapting, refactoring and reusing code. What if we applied that same principal to dealing with whatever framework we're using?

He goes on to look at the "framework is not your application" concept and fleshes it out with examples of it applied to a few different topics: Controllers, Models and ORMs. He also shows how, through the use of something like Doctrine's EntityManager, you can easily abstract things out so the internals of the application can easily split the application and framework.

0 comments voice your opinion now!
decouple framework controller model orm doctrine entity

Link: http://kristopherwilson.com/2013/11/27/decoupling-the-framework/

Developer Drive:
Introducing Laravel, part 2
October 28, 2013 @ 13:18:51

The Developer Drive blog has posted the second part of their series introducing the Laravel PHP framework. In this new tutorial they build on the basics from part one to briefly discuss controllers and the Eloquent ORM.

In the first part of this introductory mini series we looked at simple routes and views and now we'll look at how to work with controllers and models , how these two fit in the framework and how to use them.

They explain some of the basics of controllers first including a bit of sample code showing how to output a basic view and add a new route. Following that is a brief look at using the ORM and making a model - a Post - and defining the table it relates to.

0 comments voice your opinion now!
laravel framework introduction series part2 controller route model eloquent orm

Link: http://www.developerdrive.com/2013/10/introducing-laravel-part-2/

Brandon Savage:
The myth of the untestable controller
September 23, 2013 @ 11:35:04

In this new post to his site Brandon Savage looks at the "myth of the untestable controller" and gives some tips to help resolve it.

It's a persistent statement: controllers should have as little code as possible because they're difficult, nay impossible, to test. Developers should force most of their code into the models instead, where business, validation and other logic can take place. [...] But this is not true. Controllers are no more or less testable than any other kind of code. What's more, the fact that people believe controllers are largely untestable is an excuse for writing untestable code, not a valid design decision.

He talks briefly about where the myth might have come from (Zend Framework v1, with it's difficult to test controllers) and a note that, really, controllers are as testable as you want them to be. He give three things that could help make them easier to test:

  • Using dependency injection/inversion methods
  • Refactoring to use the Abstract Factory design pattern
  • Using anonymous functions/closures over plain configuration settings
0 comments voice your opinion now!
untestable unittest controller solutions abstractfactory designpattern

Link: http://www.brandonsavage.net/the-myth-of-the-untestable-controller/

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

Rob Allen:
Injecting configuration into a ZF2 controller
April 30, 2013 @ 09:11:16

Rob Allen has a a new post to his site today showing you how to inject configuration information into a Zend Framework 2 controller via an interface and some initializer settings in the module setup.

One thing you may find yourself needing to do is access configuration information in a controller or service class. The easiest way to do this is to use the ServiceManger's initialiser feature. This allows you to write one piece of injection code that can be applied to multiple objects. It's easier to show this in action!

He includes a sample configuration file (with a setting for "setting_1") and the interface you implement to structure the load request. He then shows how to hook this into the controller and the code needed for the module "getControllerConfig" (or "getServiceConfig" for use with services) to load in the file and set it to the correct object.

0 comments voice your opinion now!
inject configuration controller zendframework2 tutorial file

Link: http://akrabat.com/zend-framework-2/injecting-configuration-into-a-zf2-controller

NetTuts.com:
Testing Laravel Controllers
April 24, 2013 @ 09:24:06

NetTuts.com has posted a new article for the Laravel users out there - a tutorial showing how to test Laravel controllers via PHPUnit tests.

Testing controllers isn't the easiest thing in the world. Well, let me rephrase that: testing them is a cinch; what's difficult, at least at first, is determining what to test. Should a controller test verify text on the page? Should it touch the database? Should it ensure that variables exist in the view? If this is your first hay-ride, these things can be confusing! Let me help.

They break up the testing process into three main chunks - isolation of the tests (mocking where need be), calling the controller method and running the checks (assertions) to be sure the result is valid. They start with a basic controller test that runs a GET request on the "posts" method. They also mention the assertion helper methods included with Laravel controller testing, things like "assertRedirectedTo" and "assertSessionHas". The article then gets into moreo practical examples showing a TDD approach to testing some simple controller calls, mocking data connections, handling redirects and repositories.

0 comments voice your opinion now!
laravel controller testing tutorial helper

Link: http://net.tutsplus.com/tutorials/php/testing-laravel-controllers

Reddit.com:
Dependency injection in ZF2 and Symfony 2 are service locators
April 16, 2013 @ 12:40:07

On Reddit's PHP section there's a discussion happening about dependency injection versus service locators in two popular PHP frameworks - Zend Framework 2 and Symfony 2 (and how they're not really DI at all).

Both ZF2 and Symfony 2 offer the same behavior: if I'm in a controller, and I want to use a service, I have to get it from the container with $this->get('my_service'). As such, the controller is not using DI, this is the service locator pattern. Controllers become more difficult to tests because of that, and they depend on the container now. I wonder why both frameworks didn't go further: why not treat controllers like services and use dependency injection on them. In other words: if a controller needs a service "A", then it should get it in the constructor, or through setter/property injection.

The comments talk some about the "controller from the DI container" idea, some other ways around the problem and some clarification as to what the frameworks are actually doing related to the container injection.

0 comments voice your opinion now!
dependency injection service locator controller framework zendframework2 symfony2

Link: http://www.reddit.com/r/PHP/comments/1caidn/dependency_injection_in_zf2_and_symfony_2_are

NetTuts.com:
Taming Slim 2.0
April 02, 2013 @ 09:17:11

On NetTuts.com today there's a new tutorial posted about "taming" Slim 2.0, the latest version of the popular PHP microframework. They look at application structure and share some tips to using this update.

Slim is a lightweight framework that packs a lot of punch for its tiny footprint. It has an incredible routing system, and offers a solid base to work from without getting in your way. Let me show you! But that's not to say that Slim doesn't has some issues; it's one-file setup becomes cluttered as your application grows. In this article, we'll review how to structure a Slim application to not only sustain, but improve its functionality and keep things neat and systematic.

He starts with an example of "vanilla Slim" and looks some at what's happening behind the scenes in the routing engine. They then give you a step by step installation and usage guide including updating the router to use class files. An example controller is included as well as some basic error handling using a Twig template for use across the application.

0 comments voice your opinion now!
slim microframework tutorial introduction class controller router error handling



Community Events











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


package introduction example podcast component composer application security hack unittest facebook install hhvm overview symfony2 release opinion framework code language

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