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:
Ardent Laravel Models on Steroids
September 19, 2014 @ 11:54:34

In Ardent, an enhancement to the model system in the Laravel framework that allows for easy configuration of validation rules.

One of the (few) things I don't like about Laravel is that you cannot move the validation code from your controller to your models easily. When I write software I like to apply the "fat models, skinny controllers" principle. So, for me, writing the validation code in the controller is not a good thing. To solve this, I'd like to introduce Ardent, a great package for Laravel 4. To be more precise, Ardent presents itself as "Self-validating smart models for Laravel Framework 4's Eloquent ORM." In other words: exactly what we need!

He introduces the library as a part of a test application, a To-Do list that includes user and task handling. He starts with the creation of the base Laravel migrations to build the tables and the code for the two necessary models. He then shows how to install Ardent and put it to use in the controller code, adding validation rules and messages for each property on failure. He also shows how to use the model auto-hydration and hooks to make working with the models even easier. He finishes off the post showing how to set up relations "the Ardent way" using a slightly different format as the usual Laravel handling.

0 comments voice your opinion now!
laravel model ardent library tutorial introduction

Link: http://www.sitepoint.com/ardent-laravel-models-steroids/

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/

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

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/

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/

Zumba Engineering Blog:
Incorporating Mongounit into Multi-datasource Models with Traits
October 31, 2013 @ 10:42:27

On the Zubma Engineering blog today Chris Saylor has written up a tutorial showing how they used traits to use multiple data sources with Mongounit, working around the single source limitations it enforces.

A while back we open sourced Mongounit, a PHPUnit extension for testing models utilizing mongodb. One key issue that we've discovered as we incorporate MongoDB into more of our data models is that extending Mongounit's TestCase class limits that unit test towards Mongo only as the datasource. Since only a portion of our data is in Mongo while the remaining is in MySQL, limiting a test case to work with one datasource or another is too limiting.

They tried two other solutions first, separating out the tests by data source and manually clear the Mongo data in the tests, but both ran into problems. Instead, they opted to use traits to provide drop-in Mongo testing support as needed. It provides a simple interface to set up and tear down the needed Mongo resources - an example of which is also provided in the post. The code for the trait can be found on Github.

0 comments voice your opinion now!
trait mongounit unittest database multiple source model

Link: http://engineering.zumba.com/2013/10/30/multiple-data-sources-phpunit-testing/

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/

PHPMaster.com:
Lesser-Known "Features" of PHP's OO Model
July 22, 2013 @ 12:21:22

On PHPMaster.com there's a new tutorial from Lorna Mitchell about some of the lesser known OOP features that are built in to the PHP language. She talks about things like interface inheritance, private properties and autoloading and type hints.

The vast majority of today's applications written in PHP are object-oriented, and in general the core OOP concepts are pretty well understood by PHP developers. This article pushes the boundary of your understanding and shows you some tricks, or potential pitfalls depending on your perspective, of OOP in PHP.

Besides the ones mentioned above, she also looks at abstract classes and their use as well as the use of "finally" to handle the cleanup after exceptions.

0 comments voice your opinion now!
features oop model language private inheritance typehint finally

Link: http://phpmaster.com/lesser-known-features-of-phps-oo-model

PHPMaster.com:
Build a CRUD App with Yii in Minutes
July 03, 2013 @ 10:48:09

On PHPMaster.com there's a new tutorial posted showing you how to create a CRUD app with the Yii framework "in minutes." You might want to have a little familiarity with Yii before you start, but it's not absolutely required.

Yii is a high performance framework that's fast, secure, and well-suited for Web 2.0 applications. It favors convention over configuration, which means that if you follow its guidelines you'll end up writing much less code than you would otherwise (and less code implies fewer bugs). Furthermore, it offers many convenient features out of the box, such as scaffolding, data access objects, theming, access control, caching, and more. In this article I'll cover the basics using Yii to create a CRUD system.

They walk you through a basic installation and jump right in to working with controllers and routing. The rest of the tutorial is broken up into a few different steps:

  • Step 1: Create the database (MySQL in this case)
  • Step 2: Make a model to correspond to the "posts" table
  • Step 3: Click on the CRUD generator for the model

This generates all needed views and functionality to be able to create new records, update current ones, delete records and get the current data.

0 comments voice your opinion now!
crud yii tutorial application model framework

Link: http://phpmaster.com/build-a-crud-app-with-yii-in-minutes

MaltBlue.com:
Zend Framework 2 - Hydrators, Models and the TableGateway Pattern
May 15, 2013 @ 11:13:46

Matthew Setter has written up a post to his site that continues his look at the features of Zend Framework 2. This time he's looking specifically at hydrators, models and the table gateways and their use in connecting your application with a database.

One set of features has really been helping me of late ones that really have me smiling; these are: Hydrators, Models and Table Gateways. If you're new to ZF2 or database interaction with frameworks, then you're in a perfect position as today's post will be giving you a good introduction to the basics of using both together.

He starts with a look back at how it all was done in ZF1 and shows how using these three components makes for an even better system, allowing the model to be completely data-source agnostic. His examples start with the table gateway class, showing how to connect it with a "users" table. From there he adds in the model (with an "exchangeArray" method) and a hydrator that maps the table columns to the properties on the entity. He shows how to add this setup to the service configuration and its use in a controller, returning a full list of the records in the "user" table.

0 comments voice your opinion now!
zendframework2 tutorial hydrator tablegateway model database

Link: http://www.maltblue.com/tutorial/zendframework2-hydrators-models-tablegateway-pattern


Community Events





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


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

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