symfony APC cache and Memcache session storage

symfony-memcache

In a previous post I described some of the reasons why you would want to store your session data in an alternate location to temporary files on your server. I explained the setup of database session storage using Doctrine and how this would allow you to take advantage of storing session data in a database. However depending upon your application requirements storing your session data in a database may cause excessive load on you database. You could of course use a separate dedicated database server to store your session data. However there is an alternate setup that will allow you to centralise your session storage ready for horizontal scaling of your hosting e.g. adding additional web servers.

Read More »

Posted in php, symfony | Tagged , , , | 1 Comment

symfony Doctrine database session storage

Sessions are normally managed by your server and depending upon how involved you get with the PHP setup you need never know how this data is stored. The default setup for PHP is to store session data in temporary files on the server. So why would we want to change how sessions are handled and what advantage can we gain from any changes we make.

Why use database session management?

Sessions allow you maintain persistence within PHP applications. With every HTTP request a PHP application must re-assign every variable and object needed in your application. Sessions allow you to store data that is required to persist past each HTTP request allowing it to be easily retrieved and used.

Read More »

Posted in php, symfony | Tagged , , , | 7 Comments

YUI Connect asynchronous file uploads

I’m sure the problems with multi-part data that I have been working through this morning is very simple but there are a number of forum posts about this, so I will share my findings. When using YUI Connection Manager in conjunction with multi-part form data I have experienced problems creating the asynchronous request and canceling the form submission. Even after setting up the request and callback object and checking the YUI API repeatedly the problem resides elsewhere.

YAHOO.util.Event.addListener(forms, 'submit', this._onFormSubmit, this);

_onFormSubmit: function(e, o)
{
  YAHOO>util.Event.preventDefault(e);
  // Set the form
  YAHOO.util.Connect.setForm(e.currentTarget);
  // Configure the callback object
  callBackObj = {
    success: o._loadRemoteFormSubmissionTemplateComplete,
    failure: o._loadRemoteFormSubmissionTemplateFailed,
    argument: {
      objType: objType, 
      region: regionObj,  
      mode: submitbutton.value}
  }
  // Make the request
  YAHOO.util.Connect.asyncRequest('POST', e.currentTarget.action, callBackObj);
}

With non multi-part forms you can hijack the submit event of the form and create an asynchronous request. However once you try with multi-part data no matter how you set this up and attempt to cancel the form submit action the form will still make an HTTP request in the main window.

The YUI Multi-Part Data Solution

The solution is very simple once you find it but it is easy to overlook! In order to use YUI connect to create an asynchronous request you must remove the ’submit’ button and replace it with a ‘button’ then assign it an eventListener that will create the asyncRequest.

var alternateButton = document.getElementById('alternateButtonId')
YAHOO.util.Event.addListener(alternateButton, 'click', this._onFormSubmit, this);

_onFormSubmit: function(e, o)
{
  YAHOO.util.Event.preventDefault(e);
  // Set the form
  YAHOO.util.Connect.setForm(e.currentTarget);
  // Configure the callback object
  callBackObj = {
    success: o._loadRemoteFormSubmissionTemplateComplete,
    failure: o._loadRemoteFormSubmissionTemplateFailed,
    argument: {
      objType: objType, 
      region: regionObj,  
      mode: submitbutton.value}
  }
  // Make the request
  YAHOO.util.Connect.asyncRequest('POST', e.currentTarget.action, callBackObj);
}

When trying to use multi-part data YUI Connection Manager will create an iframe in the document that your form will submit the data to. If you try and use the submit handler YUI currently does not change the target value of the submit event.

The YUI examples do all show the use of alternate buttons rather than a standard submit button however it can be easily overlooked. I hope this helps someone!

Posted in JavaScript | Tagged , , | 2 Comments

Propel doUpdate update multiple records in a single statement

I’ve been very busy with a number of project launches lately. While working on a little problem today I re-discovered a little gem for use with Propel to update multiple rows in a single statement, rather than iterating through a collection updating and saving each object in turn.

This task is simple in SQL but after a while using any abstraction layer you may find like me you forget about the simple solutions as you spend you day working with complex objects and trying to hydrate custom objects. Blah blah blah…

The complex solution to a simple problem:

// Obtain the connection configured
$conn = Propel::getConnection(YourObjectPeer::DATABASE_NAME);
// Create a Criteria object that will select the correct rows from the database
$selectCriteria = new Criteria();
$selectCriteria->add(YourObjectPeer::COLUMB_TO_SELECT, 'value_to_match');
// Create a Criteria object includes the value you want to set
$updateCriteria = new Criteria();
$updateCriteria->add(YourObjectPeer::COLUMB_TO_CHANGE, 'value_to_be_set');
// Execute the query
BasePeer::doUpdate($selectCriteria, $updateCriteria, $conn);

Thats it! I hope it helps…

Posted in php, symfony | Tagged , , | Leave a comment

How to: Magento eCommerce help and tutorials

Magento how to

Magento is an Open Source eCommerce platform developed using the Zend Framework by Varien. It is a fabulously customizable and extendible platform that once mastered can allow you to develop feature rich eCommerce solutions for your clients quickly and effectively. However for some mastering the Magento platform may not be that easy.

Magento uses common design patterns such as MVC, Application Controller and Two Step View to structure the application and provide mechanisms to extend and override the functionality and presentation. The platform has a huge number of files and directories that can cause confusion for newcomers to the platform. However this extended folder structure clearly defines where the platforms core files exist and where you can place your custom code and modules. Allowing you to extend the platform without modifying the core and breaking the upgrade process.

However daunting the platform appears or skeptical you may be due to the unfamiliar concepts, invest a small amount of time with the platform and it will soon start to payoff. This list of tutorials and resources will help you get up to speed quickly. Read More »

Posted in Magento, php | 2 Comments