Get rid of var $name in CakePHP

How you can go about getting rid of var $name in CakePHP

A lot of people new to CakePHP struggle with remembering what to call and when, a common thing I see people doing inside their controller is something like;

$this->Sections->recursive = 0

When actually they mean something like;

$this->Section->recursive = 0

I think the reason the Model is sometimes pluralised is because when you look at most examples of how to write controllers the very first thing inside the class is;

var $name = 'Sections'

The reason this is included in both the Model and the Controller is to punch PHP4 into playing nice. If you require PHP4 then fair enough, but the vast majority of us use PHP5 and as such have no need for $name. So I would implore you to remove it from samples and code that doesn’t require it as some people seem to trip up over it.

Recent posts View all

Web DevProductivity

Keeping on top of website updates

Learn what website updates are, what they entail, why they are important, and how we can help

Freelancing

Getting the most out of your agency

Here are some tips based on years of working with, for, and as an agency on how to get the most out of any work you do.