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

QaFoo.com:
Code Reuse By Inheritance
January 20, 2014 @ 10:55:18

On the Qafoo blog today Kore Nordmann has a new post talking about code reuse through inheritance. He talks about base classes, sharing code and abstraction.

To me, inheritance has two properties: Defining an is-a relationship [and] making it possible to share code between classes by extending from a common base class. The is-a relationship between classes is one thing I like to use inheritance for. [...] The other thing you can use inheritance for is to share code between multiple classes. [...] I personally think that the latter is one of the worst things you can do in object oriented design. Bear with me for a moment and let me try to explain why I think that.

His example of doing it the wrong way is using the Active Record design pattern and how it's usually implemented - storage logic in the base class and business/table logic in the extending class. He then gets into an example that's a bit "smaller" creating diff display functionality and how the "code reuse by inheritance" creeps in a lot in helper methods. He also briefly looks at testing (or not testing) private methods and and the "Depth of Inheritance Tree" metric's recommended value.

0 comments voice your opinion now!
code reuse inheritance helper activerecord testing depth

Link: http://qafoo.com/blog/063_code_reuse_by_inheritance.html

SitePoint PHP Blog:
Yii Routing, Active Record and Caching
November 07, 2013 @ 09:37:31

On the SitePoint PHP blog today Sandeep Panda has a new article looking at routing, using Active Record and caching with the Yii Framework. The Yii framework is a " a high-performance PHP framework best for developing Web 2.0 applications".

Almost all modern web apps have 3 major concerns: Retrieving data from a database easily and effectively, caching the web content and URL rewriting to create user friendly URLs. Yii, like any other good framework, offers simple and easy solutions to all of the above. [...] In this tutorial we will look at how Yii greatly simplifies the development of database driven websites with its Active Record support. Additionally, Yii lets you further improve your websites by implementing user friendly URLs and powerful caching techniques.

He creates a simple application based on the Yii framework skeleton called "gadgetstore" that works with fictional phone data. He shows how to set up a few sample routes and adding the "phone" table to the database. He then uses the framework's tools to auto-generate the model and shows the save/delete operations. He then creates the "Phone" controller and an add action to handle the create submissions. Finally, he gets into caching the response data and uses the built-in "cache" function for the models to store the results of a "findAll" request.

0 comments voice your opinion now!
yii framework caching activerecord routing

Link: http://www.sitepoint.com/yii-routing-active-record-caching/

Russell Walker:
Active Record vs Data Mapper for Persistence
October 18, 2013 @ 10:19:13

Russell Walker has a new post today comparing two popular methods for abstracting out database access and working with your data - the Active Record and Data Mapper patterns for data persistence.

These two design patterns are explained in Martin Fowler's book 'Patterns of Enterprise Application Architecture', and represent ways of handling data persistence in object oriented programming.

He gives simple code examples of both - one showing a basic "save" call with Active Record and the other showing the saving of a "Foo" entity using similar logic. Along with these examples, he also includes a few points about the major advantages and disadvantages related to the pattern. He also talks some about "service objects", the go-between that the data mapper pattern uses to combine business logic and the mapper object. He ends the post by making some suggestions about which to use, depending on the need of course.

0 comments voice your opinion now!
activerecord datamapper persistence database interface designpattern

Link: http://russellscottwalker.blogspot.co.uk/2013/10/active-record-vs-data-mapper.html

Simon Holywell:
Idiorm and Paris 1.3.0 released - the minimalist ORM and fluent query builder for PH
February 27, 2013 @ 10:33:33

Simon Holywell has a new post to his site about a project that aims to be a minimalist ORM library and make it easier to built queries on the fly for your applications (and is installable via Composer) - the Idorm + Paris combination.

Idiorm is a PHP ORM that eschews complexity and deliberately remains lightweight with support for PHP5.2+. [...] However, having said this, Idiorm is very powerful and it makes most of the queries PHP applications require pain free. Some of these features include fluent query building, multiple connection support and result sets for easy record manipulation. Paris sits on top of Idiorm to provide a simplified active record implementation based upon the same minimalist philosophy.

He includes examples in the post of both queries with Idiorm - simple things like creating and finding records - and using Paris to make models out of PHP objects. He also talks some about the current state of the project, recent advancements and some of the things they're looking to do with it in the future (including dropping PHP 5.2 support and use late static binding).

0 comments voice your opinion now!
library project orm idiorm paris activerecord simplicity


Zend Developer Zone:
Design Patterns I Hate
May 18, 2011 @ 10:18:21

On the Zend Developer Zone today there's a new post from Keith Casey about some of the design patterns he hates - ones that are misused too often and have become more of a "worst practice" at times than others.

To be clear, I think Design Patterns have their place. When used properly, they can make our lives easier and our code better. When they're misused - "If the only tool you have is a hammer.." - then they can become the bane of our existence. Unfortunately, some Design Patterns seem more susceptible to this than others. So maybe this is less "design patterns I hate" and more of "design patterns that have been abused beyond all sense of reason"... I'll let you decide.

He has three of the most commonly misused design patterns in his list. Anyone who has looked into using patterns in their applications will recognize them:

  • Active Record
  • Factory
  • Singleton

For each, he describes some of the bad implementations he's seen and notes that, while these are commonly abused, they can still be redeemed by being used appropriately.

0 comments voice your opinion now!
designpattern opinion misuse activerecord factory singleton


Zend Developer Zone:
New PHP5.3+ Framework Jolt
August 13, 2010 @ 10:50:05

On the Zend Developer Zone today there's a new post from Vic Cherubini about a new PHP 5.3 only framework - Jolt.

Since [I wrote a previous framework], PHP5.3 was released and added a whole slew of features. Wanting to take advantage of them, I rewrote (and renamed) the entire framework from Artisan System to Jolt. The interesting thing about Jolt is that it intentionally doesn't come with any type of ORM or ActiveRecord classes. Because I believe that Models should be fat, and controllers skinny, the model framework is left entirely up to the developer.

The README on the github repository talks about why he decided to make his own framework, some of the features and functionality it includes and an example of it in action (a boostrap file).

6 comments voice your opinion now!
framework jolt orm activerecord model example


Community News:
A PHP 5.3 ActiveRecord
May 23, 2009 @ 23:58:19

Jacques Fuentes has submitted some information about an ActiveRecord tool he's developed that's similar to the pattern found in Ruby On Rails and can be found here.

It is extremely similar to ActiveRecord for Ruby on Rails. We believe our project is offering a better programming experience than propel/doctrine since it does not require effort to get started. Propel/doctrine both require that you use yaml/xml files or column mapping in your model classes. We use show fields to 'magically' load this in the background eliminating the tedious requirement of mapping your schema to a file.

The code makes use of some of the features of the upcoming PHP 5.3 release (but won't work with versions prior to that). If you'd like to try it out, you can grab the code here.

0 comments voice your opinion now!
database activerecord php5


DevShed:
The mysqli Extension and the Active Record Pattern
April 15, 2009 @ 10:27:56

DevShed.com has posted the seventh article in their series looking at the Active Record design pattern in PHP applications. In this latest tutorial they show how to replace the older MySQL client libraries and use the newer mysqli client instead.

Well, as you'll surely recall, I built this class by using the old MySQL library included with the PHP distribution, which is good and efficient. But it's worth making the effort to see how this sample class can be rewritten by using the newer, revamped "mysqli" extension. Thus, this last episode will be dedicated exclusively to doing this, so you can have at your disposal an enhanced versions of the class.

For most of the code, you won't see too much of a change - the methods are named similarly and the results are references differently, but you shouldn't have to make too much of a change.

0 comments voice your opinion now!
extension mysqli activerecord design pattern tutorial


DevShed:
Refactoring the MySQL Abstraction Class with the Active Record Pattern
April 08, 2009 @ 07:56:18

DevShed has the latest article in their tutorial series looking at the Active Record design pattern posted today. This time they focus on a bit of refactoring to make their MySQL abstraction class a bit easier to use and work better.

As I stated in the end of the [previous] tutorial, however, some methods of this sample class implement redundant business logic, and as a consequence it's necessary to refactor them to fix this issue in a quick and simple manner. Thus, in the next few lines I'll be explaining how to accomplish this process progressively, and as always, accompanied by the corresponding code samples.

They change up some of the CRUD (Create, Read, Update, Delete) functions by dynamically constructing the SQL and updating the fetch functions to allow for more modifiers like "LIKE" or "LIMIT".

0 comments voice your opinion now!
refactor abstraction class activerecord design pattern tutorial


DevShed:
Utilizing the LIMIT Clause with the Active Record Pattern
March 31, 2009 @ 12:58:35

DevShed continues their series on the Active Record pattern in PHP with this new article implementing the LIMIT statement on your abstraction class.

In its current version, it'll be able to accomplish only a few basic database operations tasks. Therefore, this fifth article of the series will be focused on enabling the class to fetch database rows by using the LIMIT clause.

They add the LIMIT clause as a part of its own function and its own SQL statement. You define the number of rows to fetch, the table to fetch it from and the offset to start from. The SQL is passed off to their fetchRow statement and the results are returned in an array.

0 comments voice your opinion now!
activerecord design pattern clause limit abstraction layer database



Community Events





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


introduction language unittest series code experience testing list framework community opinion laravel podcast symfony2 api release developer install interview threedevsandamaybe

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