Arrays in dBs and YAML Config

I’m working on some new mega-menus for GO. I’ll post about that when we go live.

Following a pre-Christmas code review of the user-defined munu choices, we identified that we needed a way to provide a default set of menu items for everybody prior to them making and saving their personal choices. Mike remembered that we had an Option table capable of storing an array of values per person.

As this table existed in the GO symfony framework it already had methods for getting and setting values. Reading those methods introduced me to the php serialize function. This function takes an array and generates a storable representation of its value. For example this
Array
(
   [0] => 1
   [1] => 2
   [2] => 3
   [3] => 4
   [4] => 9
)

is turned into this:a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:9;}

When the value is queried we can simply unserialize it to return it to its php readable form.

Default Values in YAML Config Files

In the Option table, if a record isn’t returned for a user (no option has been set) a default value (or array) can be returned when passed into the querying method. As I needed to query the data in more than one place in the application, I needed to set the default value in one place. Symfony uses YAML files for configuration so I set it in the application config file app.yml.
all:
  sf_guard_plugin:
    default_dashbar:      [1, 2, 3, 4, 9]

Spaces are all important in YAML. Ensure you don’t indent each line and include spaces between array elements.

To pull YAML config variables into your code enter:sfConfig::get('param_name', $default_value);. The ‘param_name’ takes the file name and the parent child structure of the YAML file, separated by underscores and can be found in the Configuring Symfony chapter of the manual.

Heavy duty stuff for the first post of 2011.

Use our data

I mentioned previously about some of the feeds we’re providing for news and events and said at the end of the post that we’d be doing some stuff for the Institutional Web Management Workshop. Well it’s finally time that we have to firm up what that stuff is!

Edge Hill – along with the Universities of Aberdeen and Bath – are sponsoring the workshop’s Innovation Competition. For this we’re letting people know what data we have available for people to use in the creation of innovate, lightweight demonstrations of web technologies.

For the Big Brief we’ve restructured several of our systems to allow information to be extracted in different ways. Now as well as viewing web pages, you can use our data the way you want to or access in more machine-readable forms.

Several of these feeds we use internally – for example, the JSON feed of events is used to populate the calendar in the sidebar to show what days events are on.

It’s all work in progress so we’ll be adding more formats in the coming months but I’m really looking forward to seeing the ways people can use information from the website as part of the innovation competition.

>