Allowed memory size error in Silverstripe
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: 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.
Web Development Frameworks
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 dissertation 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:
- Ruby Gems
- Rails
- 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.
Acquia - Drupal pumped
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 :-)
Drupal 6 - Page template variables in nodes
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: 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: page.tpl.php 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: 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. 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.<?php
print theme('links', $primary_links,array('class'=>'links primary-links'));
?>
<?php
print '<pre>';
if ($_GET['do'] == 'node-att') {
print_r(get_defined_vars());
}
print '</pre>';
?>
<?php
print '<pre>';
if ($_GET['do'] == 'page-att') {
print_r(get_defined_vars());
}
print '</pre>';
?>
function phptemplate_preprocess_node(&$vars, $hook) {
$tree = menu_navigation_links('primary-links', $level = 1);
$vars['node_menu'] = theme('links',$tree);
}
<?php print $node_menu; ?>

