Sunday, June 27, 2010

CodeIgniter - Ruby on Rails (RoR) Layouts and filters


Continuing to list starter features, I have also integrated Ruby on Rails (RoR) style layouts and before / after filters.

Both were implemented as CI hooks - both the layout and filter code was obtained from the CodeIgniter forums and wiki posts

Using the Filters hook, each action is wrapped in a Doctrine Transaction, which ensures all db updates etc. are ATOMIC.

One hassle I found with the above Filters system was that I couldn't implement a before / after filter directly in the controller class. Within the Doctrine_Transaction filter I ensure that if a controller has a before_action, or after_action function within its class definition, it is called before, or after the action is executed. This obviously could / should be abstracted out eventually into its own Filter class.... but it works just the same as is.

Tuesday, June 08, 2010

CodeIgniter - Doctrine unit testing - starter features

So to expand on the previous post... specifically to describe a few of the extra bells and whistles in the project starter....

Unit Testing
I have created a (very) simple extension to the codeigniter unit testing as I wanted to have a simple, web based interface to unit tests. I found the whole CodeIgniter terminology used in unit testing a little confusing (coming from a NUnit / JUnit testing background). Unless I missed something in the doc (which is very possible), CodeIgniter supports test assertions ($controller->unit->run when the test helper is loaded), there was no way to group a number of assertions together into a logical unit of testing.

I'm going to use a little NUnit / JUnit terminology to describe unit testing via the web page interface in the starter. In the ApplicationCode/libraries folder I have a base_test_controller which when extended replicates basic TestFixture functionality. To create a Unit Test within the fixture, simply create a function prefixed with the name test_. The following demonstrates using a controller as a test fixture:

// My Test Fixture
class MyTest extends base_test_controller {
// This method is executed before any test methods are run
function fixture_setup(){}
// This method is executed after all test methods are run
function fixture_tear_down(){}
// This method is executed before each test method is run
function unit_setup(){}
// This method is executed after each test method is run
function unit_tear_down(){}

// Your Unit Test
function test_My_unit_test()
$this->test_description = "This is a description of my unit test";

$this->unit->run(true, true, "Assertion one has passed");
$this->unit->run(true, true, "Assertion two has passed");

Saturday, June 05, 2010

PHP, CodeIgniter, Doctrine and ExtJS

So, its been ages since I have posted anything on this particular blog, so time for an update.

Although I still dabble with MS technologies, I find the bulk of my development has moved to MVC geared frameworks (ideally rails based) - which (I find) works best within the contexts of dynamic languages..... so I have been using platforms like Ruby, JRuby, PHP, even ColdFusion for the last few projects. My tech stack of choice is:

ExtJS : client side JS library
JRuby : presentation tier
Java + Hibernate : domain + data layer

In the latest project however I have been developing a survey site in PHP. I thought that to save anyone else time, I have created a 'project starter' development stub which incorporates:
  • ExtJS 3.2.0: client side JS library,
  • CodeIgniter 1.7.2: presentation + domain tier,
  • Doctrine 1.2: ORM data layer framework

The idea being that you can simply extract and develop, without wasting time integrating all the techologies so that they work together....

Some features of this project starter are:
  • CodeIgniter Models have been replaced with Doctrine Records
  • Doctrine is loaded into CI as a plugin
  • RoR type before and after filters....
  • Doctrine transactions automatically wrapped around every action at execution time (ATOMIC db updates)
  • Basic Role based security (I think Redux may be in there as well?)
Simply extract, hook up the database.php config file and viola.... You can start coding your layouts, views and models.

Licensing: refer to all integrated frameworks licensing agreements for details (i.e. Doctrine, ExtJS, CodeIgniter). Original licensing agreements are bundled in the Project starter for your reference. The Project starter is a freely distributed, open source integration of technologies. Just make sure that you are using each framework in adherence to their respective licensing terms. As far as I am aware all technologies can be freely used under GPL....