Richard's blog

Richard's picture

Quick Tip: Drupal Drush Out of Memory Error on Ubuntu

I recently started running into out of memory errors while running Drupal's awesome Drush module from the command line to update a sites modules.

This is odd as on my dev machine I've set up my php.ini to reserve 512MB of RAM (memory_limit=512M). That should be plenty!

I temporally upped the RAM to 2GB(!!) and was still getting out of memory errors when running Drush!

Richard's picture

PHP function any_in_array - tests if any of $needles are in $haystack

Just a quick post. You might find this useful. It compares one array ($needles) against another ($haystack) and returns true if any element of $needles is present in $haystack

Richard's picture

MySQL: Disable foreign keys while updating database

Originally found here: http://www.stetsenko.net/2008/10/mysql-how-to-ignore-checking-of-foreign-key-constraints-for-innodb-tables/

Making a note of it here because it always take me a while to find the above article.

You can switch off checking of foreign keys while you truncate/populate the tables in a MySQL database with:

SET FOREIGN_KEY_CHECKS = 0;

and re-enable it with:

Richard's picture

CakePHP Quick tip: Adding CSS links to $scripts_for_layout in 1.3

Got caught with this one upgrading from an older version of CakePHP to 1.3

In your view, to add a css file to the $script_for_layout variable, you used to do this:

<?php $html->css("css_file", null, array(), false); ?>

In 1.3, you have to change this to:

Richard's picture

Quick CakePHP Tip: Prefix/Admin Routing and form->create()

A quick tip to get your forms to play nice with admin routing:

/views/users/edit.ctp

<?php echo $form->create("User", array("url" => $html->url(array("admin" => true), true))) ?>

Why? For some reason, $form->create() ignores the usual routing prefix attribute ("admin"=>true) so you have to pass the url through $html->url() which does take prefix routing into account.

Richard's picture

einstein_www


einstein_www
Originally uploaded by richardathome

 

Richard's picture

CakePHP: Extend PaginatorHelper to indicate sort field and direction

Here's a quick piece of code that extends the default CakePHP PaginatorHelper
to add css classes to the sort column links to indicate which field is being sorted by,
and which direction:

/app/views/helpers/ex_paginator.php:

Richard's picture

CakePHP: Pagination with Containable

Took me a little while to work this out so I'm blogging it here in the hopes it will help someone in the future:

Need to Contain your Paginated data?

in your controller:

$this->paginate = array(
	"contain"=>array(
		// usual contain array
	)
);
 
$this->set("data", $this->paginate("Model"));

For example, to bring back and paginate a User (id, first_name, last_name) and their Title (Mr, Mrs, etc.):

/app/users_controller.php

Richard's picture

Must Have Software

I'm about to put together a new PC at home. Here's a mental reminder to myself about what software I can't live/work without:

Richard's picture

CakePHP: Smarter links

The Problem

There's a couple of things I wish were present in CakePHP's excellent HtmlHelper.

  1. Links should automatically add a class to themselves when they are a) pointing to a resource in the same controller and b) pointing to themselves.
  2. Able to show/hide themselves.

Why is #1 important? Imagine a primary navigation that runs across the top of a page:

Syndicate content