Zend Framework: MongoDB session saveHandler

31 05 2011

In this third part about the Zend Framework i am diving into the world of Zends implementation for sessions. Sessions are used to provide a way to save data between different page requests.

The Zend Framework has an easy way of managing sessions by creating a new instance of the Zend_Session_Namespace class. This class provides an easy to use API on the Zend_Session managed superglobal $_SESSION. By default the session data is saved to the filesystem which works perfect for simple applications using a single webserver but will be more problematic when multiple webservers are used all with their own filesystem.

A solution for this problem is saving the session data to a central database which is available to all webservers. The Zend Framework provides a class which can be used for this: Zend_Session_SaveHandler_DbTable which can be configured completely as a resource within the application.ini file.

Using the database as a central source for session data gives some other worries though:

  • You have to make sure the database will be available at all time
  • Clustering databases for high availability is something not all persons have knowledge on
  • Managing the session tables within these databases poses some headaches when changes to the existing table are needed.

Another approach is using a memory based store like memcache, but in this post i would like to use the “new” kid in town called MongoDB, a scalable, high-performance, open source, document-oriented database. For this we are going to write a new session save handler for Zend Framework called GcLib_Zend_Session_SaveHandler_MongoDb. The source of this class can be downloaded here.

Read the rest of this entry »





JQuery Inline-Field-Label plugin: a better approach

30 08 2010

There are several  solutions available on the internet for implementing labels inside a text field as shown in the example screenshot below.

Example of inline form labels

Example of inline form labels

Most of these implementations use the .focus() and .blur() functions to add/empty the input value with the label. This approach has some drawbacks though:

  • Submitting the form will submit the label when no custom data is entered.
  • When a input field needs focus on page loading then the label is never shown.

To overcome these problems i created a JQuery plugin called inFieldLabel which adds an extra span element containing the label value and with some css this span element is projected over the input text field.
/* Inline Label class*/
span.inline-label {
position: absolute;
display: none;
}

When you start typing the span element is hided.

Usage:

1) Using default label text
$("#test1").inFieldLabel();

2) Using custom label text
$("#test1").inFieldLabel({labelText:"Type your text here..."});

3) Using an attribute value of the input text field as label text (eg. “title”)
$("#test1").inFieldLabel({useAttribute:"title"});

The full source code for this plugin can be downloaded here (updated). An example of its usage can be seen here (updated) or can be downloaded here as a packaged zip file (not updated).





CKEditor On Air: Part 2

2 08 2010

In the first part of this serie i explained the steps needed to run the CKEditor in the Adobe Air runtime and how to load data from actionscript to the CKEditor instance running in Air.

This part explains how to send the data from the CKEditor instance back to the Air application, using a new CKEditor plugin called airsave. The sources for this part are available as an update to the sources of part 1.

Read the rest of this entry »





CKEditor On Air

15 07 2010

Although Adobe has provided a new (opensource) Text Layout Framework with the release of Flashplayer 10 and Adobe AIR 1.5, i am more curious whether it was possible to use a javascript editor like the CKEditor within for example Adobe AIR.

After some searching on the web, i found out that it should be possible to use javascript/html editors like CKEditor within Adobe AIR, but little info was available on how to do that.

So this blog post describes the steps i have made to successfully integrate the CKEditor with Adobe AIR, called CKEditorOnAir. Download CKEditorOnAir.zip for full example code.

Read the rest of this entry »





PHP OCI extension for Oracle: Execution Mode

11 05 2010

In the PHP world it is common to use an open source database like MySQL for persisting data. But this post is about a less common used database – Oracle – and especially the execution mode found in the PHP OCI extension for Oracle.

The PHP OCI extension for Oracle provides two execution modes: OCI_DEFAULT and OCI_COMMIT_ON_SUCCESS. The default execution mode is OCI_COMMIT_ON_SUCCESS and this mode will automatically commit any (successful) SQL statement. The OCI_DEFAULT mode is mostly used when multiple statements are executed in one batch and should be committed (or rolled back) as one transaction.

Although most PHP developers (and PHP frameworks like Zend Framework) are using the OCI_COMMIT_ON_SUCCESS execution mode as their default mode, I personally think that you should not use this mode: Using the OCI_COMMIT_ON_SUCCESS mode will auto-commit any successful SQL statement, even when a SELECT statement is executed!

Read the rest of this entry »





Zend Framework: Application resources

27 10 2009

In this second part of my Zend Framework quest, i will dive in the wonderfull world of application resource plugins. Zend_Application provide several standard resource plugins for database access, session management, routing etc. You can find more info about these standard Resource Plugins here.

The fun part of these Resource Plugins is that they can be configurated completely within the application.ini (or application.xml) configuration file and are loaded automatically by the Application Bootstrapper.  For example you can define a new Route resource “myroute” referencing the module/controller/action without writing any code like this:

; Router resources
resources.router.routes.myroute.route = "hello/:myname"
resources.router.routes.myroute.defaults.module = "mymodule"
resources.router.routes.myroute.defaults.controller = "index"
resources.router.routes.myroute.defaults.action = "index"

Which will route the following url “http://localhost/hello/world” to the standard controller action from the “mymodule” module, with the request parameter “myname”  filled with “world”.

While Zend Framework ships with a number of standard resource plugins, the intention is that developers should write their own to encapsulate their own initialization needs. So lets begin with our own custom resource plugin for initializing application logging using Zend_Log.

Read the rest of this entry »





Zend Framework: Project setup

7 10 2009

It has been a while since i last wrote a post about working with the Zend Framework and the, then rather new, package Zend_Amf. The project structure was an attempt to integrate the Zend MVC with Zend Amf (and of course try out some new features in the Flash player 10).
Since that post, Zend has released some major releases with some rather big changes, like the Zend_Application package combined with the Bootstrap class.

Because i am not a real PHP programmer (consider myself as a junior in that area), it is rather difficult to learn all the ins-and-outs of the framework and i rely heavily on what other people write on the internet about the several topics considering the Zend Framework.

So i decided to bundle all my findings into one project setup and publish the sources on Google code. This way i always have access to these sources and i can refer to them within coming blog posts.

Read the rest of this entry »





Fileupload using Zend AMF, RemoteObject and Flash 10

19 04 2009

In one of my earlier posts i described a method for uploading files using the RemoteObject class found in the Flex SDK. For the “back end” i used the still very popular amfphp implementation of the AMF protocol.

Wade Arnold the maintainer of amfphp is also involved in another implementation of the AMF protocol which is shipped with the Zend Framework. After reading some blog posts about this “new” package called Zend_Amf, i decided to give it a try.

Download ZendAMFUpload.zip for full example code.
Read the rest of this entry »





Fileupload using AMFPHP, RemoteObject and Flash 10

15 03 2009

File upload with Adobe Flex is a common asked feature for lots of applications. There are several posts on the internet to be found which explain, in detail, how to do this.

Most of these examples however uses the http protocol to transport the binary data. With the arrival of the Adobe Flash 10 player and the new FileReference features that comes with it, it is now also possible to upload a file via a RemoteObject service call.

Read the rest of this entry »





Localized flex login using the Swiz framework

7 03 2009

After reading some blogs about a relative new Flex framework called swiz, i decided to try it out some time. Swiz is a framework. started by Chris Scott, that aims to bring complete simplicity to RIA development.

To get some feeling with the framework i started to work out a login example i found on the blog from Sönke Rohde, which uses a utility for mocking service calls, which also can be found in the swiz framework. For my own example i used the following snapshot swiz-0.0.5-010609.swc with mediator and event type checking support, but decided to extend the login sample with some runtime localization features.

These localization features consist of some xml-files which can be loaded during runtime and are used for translating labels and fault messages (bad credentials).

During development of the new example i found out that the mockutility in the framework only returned a result. In a real-life application faults will occur so i copied the sources of the swiz framework TestUtil class into a new class called MockUtil and added my own mockFault and mockFaultEvent methods.

The sources of my extended login example can be downloaded here (swiz library not included!). The assets/data/users.xml file contains the mock data for the login and can be modified with your own user credentials. The assets/locale directory contains sub-directories with the localization files used.