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_helper.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:

Richard's picture

CakePHP: Auto populating foreign key dropdown fields

One of the neet features of CakePHP's scaffolding is that it automatically populates your foreign key (belongsTo, hasAndBelongsToMany) fields in your forms.

Lets take a look at a simple example to illustrate this:

app/models/article.php:

class Article extends AppModel {
	var $hasAndBelongsToMany = array(
		"Tag"
	);
}

app/models/tag.php:

Richard's picture

GeekUp Sheffield: The Aftermath

Last nights GeekUp was a lot of fun. Finbarr's presentation on making Agile pay was very informative and my talk on CakePHP went off without a hitch (apart from a minor technical hiccup with the hardware at the start).

As my first presentation, I was looking to learn as much as I could from the experiance. Here's what I came away with:

Richard's picture

GeekUp Sheffield April 1st: CakePHP Presentation

GeekUp LogoNext Wednesday (ironically April 1st) I'll be doing a short (30 minute) presentation about the CakePHP framework to the good people at Sheffield GeekUp.

This is the first time I've ever done a 'proper' (ie. one that was planned and prepared) presentation and as you might expect I'm a bit jittery.

Richard's picture

Welcome to Richard@Home

Hi there :-)

Welcome the Richard@Home's new Drupal powered blog. If I have any regular readers left, you will have seen this site evolve through a few incarnations:

Syndicate content