@Hello.respond_to do |welcome|
  welcome.to_my_blog
end

Zend Cache Error – Silverstripe 2.4 admin

Posted: June 20th, 2010 | Author: Ed | Filed under: Blog, Coding, Content Management Systems, PHP, Silverstripe | Tags: , , , | No Comments »

After uploading a new site built on Silverstripe 2.4 to my shared host, the following error reared it’s head when trying to access the admin area.

[User Error] Uncaught Zend_Cache_Exception: cache_dir is not writable

After some searching through the Silvstripe forums, I finally ended up at finding a resolved support ticket that showed an easy solution in the mysite/_config.php.

First, check the silverstripe-cache folder exists in your site’s root directory, and ensure it is writable.

Then add the following line anywhere in your _config.php file.

$_SERVER['TMPDIR'] = '/absolute_path_to_your_cache_foler/silverstripe-cache';

Finally revisit your admin with flushed cache (/admin?flush=1)

This fix worked fine for me but I have seen it hasn’t worked for others. A last case solution for those that need a quick fix would be to edit the cache directory in /sapphire/thirdparty/Zend/Cache/Backend/File.php.  Change:

protected $_options = array(
'cache_dir' => 'CHANGE_TO_CACHE_DIR',
'file_locking' => true,
'read_control' => true,
'read_control_type' => 'crc32',
'hashed_directory_level' => 0,
'hashed_directory_umask' => 0700,
'file_name_prefix' => 'zend_cache',
'cache_file_umask' => 0600,
'metadatas_array_max_size' => 100
);

The file is part of the Sapphire core so this solution is not advised as a long term fix, and could quick easily be overwritten in future updates.


Allowed memory size error in Silverstripe

Posted: June 19th, 2010 | Author: Ed | Filed under: Blog, Coding, PHP | Tags: , , | No Comments »

Silverstripe have made great improvements in the memory consumption in version 2.4 but the admin area can still get the frustrating error message.

Fatal error: Allowed memory size of 268435456 bytes exhausted

There are a few options to fix the issue:

  1. In mysite/_config.php – Add ini_set(“memory_limit“, “64M”)
  2. In .htaccess – Add php_value memory_limit 64M

Personally, I have found the 2nd option to be the best and most reliable throughout the website.

Some shared hosts lock down the options to increase memory limits so some digging around the support docs might be required if the above don’t work.


MailChimp – Usability at its very best

Posted: January 23rd, 2010 | Author: Ed | Filed under: Nice sites | No Comments »

With it’s funky post monkey mascot, the MailChimp website puts a smile on your face whenever you visit.

Not only do MailChimp paint a pretty picture but their website and online service is one of the easiest and best I have used.  The front of house design is simple, informational and markets the service clearly to encourage sign up (not just because it is free!).

Mail Chimp Email Marketing

Once signed up, MailChimp’s user interface guides you through every step of the process so well I could hardly fault it.

It really does lead the way in web application interface design and worth a look if you’re a web designer.

Check it out – http://www.mailchimp.com


Web Development Frameworks

Posted: January 23rd, 2010 | Author: Ed | Filed under: Coding | No Comments »

After spending time with retro coded content management systems like Drupal, I started getting frustrated with developing.  I started reading about web development frameworks on blogs like Sitepoint & Smashing Magazine.

Content Management Systems definitely have there place in the market to quickly build templated websites that you can hand over to clients but web frameworks are now my option is a project is more bespoke.

I tried a lot of different frameworks, although most were very briefly tested due to my impatience.  The ones that really stood out for me were:

  • Codeigniter – PHP
  • Django – Python
  • Ruby on Rails – Ruby

Each framework has its good points and its bad points.

Django has received great press over the past year with people raving that it is super fast, and quick to develop on with it’s built in admin scaffolding.  I just didn’t get on Python, its indentation and need to now classes to import.  I had a fiddle around but unfortunately don’t have enough knowledge to share with you.

Codeigniter – www.codeigniter.com

When I started trying out CodeIgniter, one of the big pulls for me was Ellis Labs, the framework creators.  They were also (at the time) working on rewriting their popular and highly regarded content managment system Expression Engine on the Codeigniter framework.  I saw a good mix.  A CMS for quickly building templated websites and a framework for building bespoke projects.  I checked for updates on the release of Expression Engine for over 8 months with promise of a beta soon.  Sorry Ellis Lab, I just got board of waiting and went elsewhere.

That being said, CodeIgniter does rock.

Setup & Installation

The first PHP framework that caught my eye, Codeigniter was VERY easy to setup and get started.  Simply download, drop in your desired folder and away you go.  The documentation is also really helpful to get started and show the ropes.  The community is very active with plenty of users in the forum and new blogs popping up with extensions.

Coding

Built using the MVC pattern, and with plenty of classes built in, it is easy to see results quickly.  Every class in CodeIgniter extends from the “Super Object” so the code is consistent and clean when learning.

$this->load->view('myform');

Unlike frameworks such as Cakephp, CodeIgniter doesn’t have “automagic” that loads classes and requires you to be more verbose in the controller.

$this->load->library(‘form_validation’);

Frequent used classes can be loaded in the config but this can slow down your app if used too much.

Speed

In benchmark tests on various blogs such as Avnet Labs, CodeIgniter is the fastest of the PHP frameworks… by some way

Community & Documentation

Codeigniter’s User Guide is great.  Hands down one of the best I have used.  It is so easy to read and quick to go through that I got through it in an evening and was building apps straight away.

The community Wiki has a good selection of libraries for authentication and databases extensions.

Ruby on Rails – www.rubyonrails.org

A few years ago a friend of mine asked me for help with his web development disertation for university.  He said “my lecturer has told to give Ruby On Rails ago.  He said it is going to be the next big thing”.  My response to him was “what the hell is Ruby On Rails?  I’ve never heard of it, and it sounds a bit Tomy-like. I would stick with PHP if I were you mate”.

Needless to say, he took my advice because he wanted help with his project.  Admitably, Rails was in it’s early days when I spat my advice out but I am eating my words now!  I’m partly wondering if I really give the best advice?.

Setup & Installation

Getting my development environment setup was pretty straight forward on my Mac.  Ruby is pre-installed with OS X so you just need a few extras to get started:

  1. Ruby Gems
  2. Rails
  3. A database

Alternatively, just download Aptana (Radrails) and get everything except the database.  Aptana is a great IDE for Rails and includes a simple to use GUI for running servers, generators and rake tasks.

Coding

Having never used Ruby before, there was an extra learning curve to get started on rails.  Ruby is a very simple language to learn and once I grasped the new idioms and syntax such as symbols and instance variables, I could confidently get around.

One of the things I really loved when I got started was the ease and ability to interact with the database through ActiveRecord.  What used to take a few lines in PHP can be done in one line using Ruby On Rails.  Being impatient, I like it when things can be done quickly.

Ruby on Rails advocates the use of RESTFUL Routing which is great when coding from a standard “Scaffold Generated” Controller.  It has taken a few reads of the Rails guide to get an understanding of how non standard routing can be used in harmony.

Speed & Deployment

Rails can be deployed on a variety of servers that each have their own performance.

  • Mongrel Cluster
  • Passenger for Apache

Reading the same Avnet Labs as seen for Codeigniter, Ruby On Rails ranks up there with CodeIgniter if not slightly faster on average in other blogs tests.

Rails includes 3 environments, Development, Testing and Production.  Each environment can be configured individually to suit the relevant setup required such as database or caching.

Deployment to the Production environment was pretty tricky the first few times due to required gems and knowing whether the Mongrel Cluster was active (which took a while to find out).  I actually got really frustrated when I tried to move my first Rails app to its production environment and wished for Codeigniter’s simple ftp upload.

As with many things to do with Ruby On Rails, simplicity and automation are key to a happy life.  I would strongly suggest checking out Capistrano that will automate all those tedious processes you need to go through when updating your app such as version control and restarting the application server.

Ruby on Rails hosting isn’t nearly as available as PHP and therefore don’t expect many budget hosts to provide it, at least not flexible enough to allow gem installations. Picking the right hosting can be quite costly when choosing a managed provider but if you don’t mind getting your hands dirty in a VPS, I would recommend having a look at providers such as SliceHost.  Their setup and installation guides are great!

Community & Documentation

Although quite young, the Rails community has boomed over the past few years since I brushed it off.  There are plenty of forums and blogs to extend the verbose documentation provided at http://guides.rubyonrails.org/.

With the exciting merge of Merb in Rails 3, I am sure the community will get even bigger with plenty more contributions provided through GitHub.


Drupal Add classes and id to body tag

Posted: February 3rd, 2009 | Author: Ed | Filed under: Coding | 1 Comment »

Drupal body class settings can be customised easily with a quick tweek of the template file.

One of the most important class/id elements in CSS is the one defined in the body.  It allows for the rest of the styles on the page to be inherited, reducing duplication.  Styles can also be overridden dependant on the page that is being rendered.

Drupal’s theme engine allows complex functions (held in template.php) to be called from the template files (e.g. page.tpl.php).

Template.php

The function shown below can create a whole bunch of attributes to live in the html body tag. Two attributes will be populated:

  1. Id
  2. class

So here is the code for template.php:

<?php

function phptemplate_body_attributes($is_front = false, $layout = 'none', $type = "", $nid) {

if ($is_front) {
$body_id = $body_class = 'homepage';
}
else {
// Remove base path and any query string.
global $base_path;
list(,$path) = explode($base_path, $_SERVER['REQUEST_URI'], 2);
list($path,) = explode('?', $path, 2);
$path = rtrim($path, '/');
// Construct the id name from the path, replacing slashes with dashes.
$body_id = str_replace('/', '-', $path);
// Construct the class name from the first part of the path only.
list($body_class,) = explode('/', $path, 2);
}
$body_id = 'page-'. $body_id;
$body_class = 'section-'. $body_class;

//Add Model to class if on Product page
//if ($node->)
$body_class .= " type-". $type;

//Find model taxonomy if on a product page

$tax = taxonomy_node_get_terms($nid);

foreach ($tax as $item){
$body_class .= ' model-'.$item->name;
}

//Split Node term string and replace space with
$body_class .= " ". str_replace(" ", "-", trim($node_terms));
// Use the same sidebar classes as Garland.
$sidebar_class = ($layout == 'both') ? 'sidebars' : "sidebar-$layout";

$body_string = " id=\"$body_id\" class=\"$body_class $sidebar_class\"";

return $body_string;
}

?>

Firstly, we determine if we are on the homepage. If so, we add homepage to the class and id strings.

If we are not on the homepage, we grab the url for the page and break it down. Grab the name and add it to the class and id strings.

We might want to style node types in different ways so lets add that to the class string

$body_class .= " type-". $type;

If we use use taxonomy on the website, we could bring in the page terms too.

$tax = taxonomy_node_get_terms($nid);

foreach ($tax as $item){
$body_class .= ' model-'.$item->name;
}

//Split Node term string and replace space with
$body_class .= " ". str_replace(" ", "-", trim($node_terms));

The standard Garland theme has styles in the body to show which sidebars are shown. We shall keep this in our class too.

$sidebar_class = ($layout == 'both') ? 'sidebars' : "sidebar-$layout";

Finally, we want to bring our class and id variables together to form the html that should be returned to the template.

$body_string = " id=\"$body_id\" class=\"$body_class $sidebar_class\"";

return $body_string;

Page.tpl.php

Adding the function to the template file is very simple.  If you are currently using the Graland theme, you will simply need to replace:

<?php print phptemplate_body_class($sidebar_left, $sidebar_right); ?>

with

<?php print phptemplate_body_attributes($is_front, $layout, $node->type, $node->nid); ?>

Simple!

Something extra

If you want, you can add extra little bits of functionality to the code.  For example, if you use Google Maps on your “Contact us” page, you will need the onload attribute.  We don’t want onload to show on other pages though so we can add a little conditional to the function just above return $body_string.

if ($body_id == 'page-contact-us.html'){
$body_string .= " onload=\"load()\" onunload=\"GUnload()\"";
}

et Voila…


Acquia – Drupal pumped

Posted: February 2nd, 2009 | Author: Ed | Filed under: Coding | No Comments »

We have recently started using the Acquia version of Drupal at work for the past couple of months.

Acquia is the commercially supported version of Drupal backed by the main man himself Dries Buytaert.  With a variety of packages available, the support and auto-updates can be very helpful.  We have found that even though Drupal is opensource, it can be difficult to recieve the help and support you need to keep projects on track.  The packaged support with Acquia can help us get help a little quicker it used to be keeping the boss happier the project is keeping on track.

In my eyes, the main benefit of the system is the pre-installed modules packed into the original downloader.  No longer do you need to drag in all those must have modules such as Views, CCKs, Imagecache, etc… that you use in basically every project.

And don’t fret if you don’t want to pay for the support but want the pre-installed modules.  Simply download the free base pack, install and then disable the Acquia modules.  You will then have a loaded copy of Drupal to begin your project!

Sweet :-)


Proving Brown works on screen

Posted: November 19th, 2008 | Author: Ed | Filed under: Nice sites | No Comments »

My first impression when I think of brown as a primary website colour is… “Er, that is going to be a bit drab”. Noe Design Studio have fired some life back into the earthy colour for me though.

I love the simplicity of the website design with the menu and sprectrum cloud in the header.

Visit Noe Design


Creative Web Specialists

Posted: November 17th, 2008 | Author: Ed | Filed under: Nice sites | Tags: , | No Comments »

I bookmarked this Warren Buckley’s website a while back and have been back various times for inspiration.  I think the more organic photo background websites are becoming alot more popular.  Just bring on the death of IE6 so we can have transparency in comfort.


Drupal 6 – Page template variables in nodes

Posted: November 17th, 2008 | Author: Ed | Filed under: Coding | Tags: , , | 2 Comments »

I have just completed working on a Drupal project that required a slightly different coding practices to the normal Drupal theme.  In order to meet the clients design, the inside pages needed to have the 2nd level of the primary menu defined inside the node.

Normaly, the primary menu is defined in page.tpl.php using:

<?php
print theme('links', $primary_links,array('class'=>'links primary-links'));
?>

but this is restricted to the variables in page.tpl.php and not accessible in node.tpl.php. Creating the link is actually very simple.

Out of the box, Drupal has two type of theme variables, “Page” and “Node” variables.  A complete list of available variables can be found at Matt Vance’s Minezone blog.  A handy trick when debugging the variables in your page and node template is to use Drupal’s get_defined_vars(); function at the bottom of the template files.  I wrap them in a quick if statement so i can switch them on when required.

Node.tpl.php:

<?php
print '<pre>';
if ($_GET['do'] == 'node-att') {
print_r(get_defined_vars());
}
print '</pre>';
?>

page.tpl.php

<?php
print '<pre>';
if ($_GET['do'] == 'page-att') {
print_r(get_defined_vars());
}
print '</pre>';
?>

Now we can see all our available variables we can add some new ones.  Drupal 6 handles the creation of theme variables slightly different than Drupal 5 with the introduction of the preprocess functions. To keep this post simple, we are only going to look at no.8, “engineName_preprocess_hook”.

The preprocess function is new to Drupal 6 and basically does what it says on the tin.  It is preprocessed to setup variables to be available when rendering the template.

For our situation, we want to use phptemplate_preprocess_node to hook the node:

function phptemplate_preprocess_node(&$vars, $hook) {
$tree = menu_navigation_links('primary-links', $level = 1);
$vars['node_menu'] = theme('links',$tree);
}

Inside our function, we have called menu_navigation_links to return an array of the primary links.  In this case, I only required the sub menu items for the current page so we pass $level=1 to say where we would like the menu to start from.  Remember this is an array so if you want to start with the top level menu items, use $level=0.

Our 2nd line defines the template variable node_menu that we theme the primary links array into links.

The final piece of the puzzle is to call the variable in your node.tpl.php.

<?php print $node_menu; ?>

And voila, you have a menu in your node.  It is simple to do but I could not find any documents related to it so hopefully this will help you.  There is so much more that can be done with the preprocess function, this is just the tip of the iceburg.


Well, Howdo world!

Posted: November 11th, 2008 | Author: Ed | Filed under: Coding | Tags: | No Comments »

After bouncing around various platforms as I always do before starting a project, I have finally settled on WordPress for my new blog. Although I WordPress is nice out of the box… I am not fully settled yet.  I have been waiting anxiously for the release of Expression Engine 2 to come out which is going to be based on the CodeIgniter framework.

I stumbled upon CodeIgniter a few months ago and have to say I am loving the quick and easy coding style it offer.  It might just be the carrot to pull me across to Expression Engine. Only time will tell. Come on Ellis Labs put us out of our misery.

My new blog is going to be my mental dumping ground of all the snippets I pickup in my work and travels around the t’internet. I currently work as an “internet consultant”, more specifically in web development, Analytics and SEO.

We all love a well designed site too so i will be sure to drop some nice sites I find along the way.

I hope you find something useful in my blog. Enjoy :-)