Archive for the ‘web development’ Category


Display Form Fields Based on Selection Using JQuery

Sunday, March 14th, 2010

This is a simple method of showing and hiding form elements based on the user’s selection. It’s based on this article with a couple of very minor changes. (Dare I say, improvements?) I’m going to assume you’ve already included the JQuery library so I won’t cover that here. I want to go straight to the code. (View the example page here.) (more…)

CakePHP: Containable Behavior is Your Friend

Thursday, February 18th, 2010

When it comes to optimizing your CakePHP queries, you need to abandon Recursive and adopt Containable.

In the example below I have the following models:

  • Patient
  • Specimen
  • Result
  • ResultType

The associations in the model are:

  • Result
    • belongsTo
      • ResultType
        • hasMany
          • Result
      • Patient
        • hasMany
          • Result
          • Specimen
      • Specimen
        • belongsTo
          • Patient
        • hasMany
          • Result

(more…)

Baseline Theme Version 1.0.1

Tuesday, February 16th, 2010

There is a new version of the Baseline Theme. In the last few days of tinkering with it and modifying it for use with this website, I noticed a small bug. The Blueprint IE reset was acting funny in conjunction with the IE8 JavaScript. I chose to make IE8.js the default with the option of including Blueprint’s reset instead. (more…)

Blueprint Optional Fancy-Type Plugin

Monday, February 15th, 2010

The Baseline Development Wordpress Theme has Blueprint plugged in already. There are some optional Blueprint plugins you can take advantage of. We’ll take a look at the fancy-type plug-in. (more…)

Why Use Blueprint and the 960 Grid System in the Baseline Theme?

Sunday, February 14th, 2010

An Inventory of Blueprint’s Style Resets and Useful Classes

A friend contacted me about using the Baseline Wordpress theme, but asked why I included both Blueprint and the 960 Grid System. The short answer is that Blueprint has a number of browser resets that I like to take advantage of and 960 GS offers greater flexibility in terms of the width of columns and their gutter widths. Especially if you want to adhere to the Golden Ratio for design. 960 pixels divides very neatly into 3.

Let’s take a look at what Blueprint does to reset some things to establish a cross-browser baseline. (more…)

Introducing the Baseline Development Wordpress Theme

Monday, February 8th, 2010

I’ve come up with some habits that I’ve developed from building themes for Wordpress over the years. One, is to start with a nearly blank style sheet. I also like to hook in several JavaScript libraries and CSS frameworks from the start to take advantage of things like JQuery, Blueprint’s CSS reset and Superfish menus. (more…)

Blueprint: Taking a Close Look at grid.css

Monday, November 9th, 2009

About Blueprint

Blueprint is a CSS framework, which aims to cut down on your development time. It gives you a solid foundation to build your project on top of, with an easy-to-use grid, sensible typography, useful plugins, and even a stylesheet for printing.

.container

/* A container should group all your columns. */
.container {
width: 950px;
margin: 0 auto;
}

(more…)

Simple Security in CakePHP

Wednesday, July 22nd, 2009

When I started to dig in to investigate using the Security Component of CakePHP, I was a bit daunted. It took me quite a while to get my head around ACL after all. Then I found this article. Here’s the crux:

The Security component will create a hash based on the form fields produced by our Form Helper. If someone tampers with the form fields (by adding or removing or changing any field), the hash is not going to match with the expected one and the add() action will fail.

Yep, it’s that simple.

Really? It just can’t be that easy, can it? Yes. It can. I simply added the Security Component to my controller like so:

var $components = array('Security');

Sure enough, when I reloaded a page with a form in my browser, this hidden field was there:

<input id="TokenFields1483167134" name="data[_Token][fields]" type="hidden" value="f513aebc448fabe42c7feedf31d43fa5bd71ec79%3An%3A0%3A%7B%7D" />

I installed a Firefox Add-on that allowed me to tamper with the POST data, and when I submitted the form, it failed, or in CakePHP terms, it was “Blackholed.” Awesome.

This isn’t going to protect me from all attacks, but it certainly is a good, easy start to implementing security in my application.

Roll Your Own CakePHP Components

Friday, May 22nd, 2009

As someone who is not formally trained as a programmer, I often understand concepts long before actually putting them into practice. Don’t Repeat Yourself (DRY) seems simple enough. Of course I don’t want to repeat myself while programming. Who wants to dig through lines of code to find a litte snippet of logic you once wrote? Still, when you’re pressed for time, sometimes you just have to Get Things Done (GTD). So best practices go through the window and you hammer out some spaghetti code so you can move on.

It’s only recently, since I’ve slowed down to finally understand how to write CakePHP Components, that I’ve realized that DRY enhances GTD. Now that I’ve got it all straight in my head, I’m a component evangelist.

At this point I’m going to assume that you’re familiar with MCV architecture and its benefits. Once in a while there’s a bit of logic that you find yourself coding into a controller that you realize you’re going to want to use in other controllers. It’s not specific to the model. That’s where components come in. They’re bits of logic that can be used by more than one controller. Let’s look at a simple one that converts mm/dd/yyyy dates to a Unix timestamp.

<?php
 
class DateComponent extends Object {
 
	function mkTimestamp($sentdate, $senttime){
 
		$thedate = explode('/', $sentdate);
 
		if(!empty($senttime)){
 
			$thetime = explode(':', $senttime);
			$newdate = mktime($thetime[0],$thetime[1],0,$thedate[0],$thedate[1],$thedate[2]);
 
		} else {
 
			$newdate = mktime(0,0,0,$thedate[0],$thedate[1],$thedate[2]);
 
		}
 
		return $newdate;
 
	}
 
}
?>

The function itself is not all that complicated. The thing is that I’m going to want to use this where ever I need to convert dates. Since the component is called “Date”, it’s named with the CakePHP convention for components: DateComponent. The file is called date.php and is saved in app/controllers/components.

Now we have to tell our controller(s) to use it. I’m using it across several controllers, so I’m adding it to app/app_controller.php by adding it to the $components var: var $components = array('Date');

Now I can access it in any controller like so: $tmsmp = $this->Date->mkTimestamp($thedate, $thetime);

The whole point is that components don’t have to be complex, they’re just code you want to reuse that doesn’t necessary apply to one model. They will save you time and clean up your controllers.

CakePHP Console ACL Help File

Sunday, March 22nd, 2009

Every now and then I want to view my help files in pretty, formatted HTML instead of plain text in a text editor or terminal window. Right now I’m working on setting up some Access Control Lists (ACL) in the CakePHP Console. ACL is a powerful, yet sometimes hard-to-grasp concept. I always figure that if I want a resource like this, there has to be someone else out there who does, so for your reference and mine, here it is. (By the way, to get to this from the console, simply type cake acl help.)

Usage: cake acl <command> <arg1> <arg2>...
———————————————–
Commands:

create aro|aco <parent> <node>
Creates a new ACL object <node> under the parent specified by <parent>, an id/alias.
The <parent> and <node> references can be in one of the following formats:

  • – <model>.<id> – The node will be bound to a specific record of the given model
  • - <alias> – The node will be given a string alias (or path, in the case of <parent>),

i.e. ‘John’.  When used with <parent>, this takes the form of an alias path,
i.e. <group>/<subgroup>/<parent>.
To add a node at the root level, enter ‘root’ or ‘/’ as the <parent> parameter.

delete aro|aco <node>
Deletes the ACL object with the given <node> reference (see ‘create’ for info on node references).

setParent aro|aco <node> <parent>
Moves the ACL object specified by <node> beneath the parent ACL object specified by <parent>.
To identify the node and parent, use the row id.

getPath aro|aco <node>
Returns the path to the ACL object specified by <node>. This command is useful in determining the inhertiance of permissions for a certain object in the tree.
For more detailed parameter usage info, see help for the ‘create’ command.

check <aro_id> <aco_id> [<aco_action>] or all
Use this command to check ACL permissions.
For more detailed parameter usage info, see help for the ‘create’ command.

grant <aro_id> <aco_id> [<aco_action>] or all
Use this command to grant ACL permissions. Once executed, the ARO specified (and its children, if any) will have ALLOW access to the specified ACO action (and the ACO’s children, if any). For more detailed parameter usage info, see help for the ‘create’ command.

deny <aro_id> <aco_id> [<aco_action>]or all
Use this command to deny ACL permissions. Once executed, the ARO specified (and its children, if any) will have DENY access to the specified ACO action (and the ACO’s children, if any). For more detailed parameter usage info, see help for the ‘create’ command.

inherit <aro_id> <aco_id> [<aco_action>]or all
Use this command to force a child ARO object to inherit its permissions settings from its parent. For more detailed parameter usage info, see help for the ‘create’ command.

view aro|aco [<node>]
The view command will return the ARO or ACO tree. The optional id/alias parameter allows you to return only a portion of the requested tree. For more detailed parameter usage info, see help for the ‘create’ command.

initdb
Uses this command : cake schema run create DbAcl

help [<command>]
Displays this help message, or a message on a specific command.

The ‘create’ help file

Usage: cake acl <command> <arg1> <arg2>…
———————————————–

  • Commands:
    • create aro|aco <parent> <node>
      • Creates a new ACL object <node> under the parent specified by <parent>, an id/alias. The <parent> and <node> references can be in one of the following formats:
        • - <model>.<id> – The node will be bound to a specific record of the given model
        • - <alias> – The node will be given a string alias (or path, in the case of <parent>), i.e. ‘John’.  When used with <parent>, this takes the form of an alias path, i.e. <group>/<subgroup>/<parent>. To add a node at the root level, enter ‘root’ or ‘/’ as the <parent> parameter.