CakePHP 2.0 Read Recursive
This is something that caught me out several times when I was new to CakePHP, so I thought I would post it here in case you are in a similar situation.
Basically I was hitting issues that when I was viewing the variables available to a view (using the CakePHP Debug Toolbar) were I was noticing that I was bringing back far more information than I needed (and occasionally, not enough)
Bringing back too much information is never a good thing, it is inefficient and a possible security leak.
The reason for this is that in CakePHP the Read, Find or FindAll takes in a value called Recursive.
To set the level of recursion you do something similar to the following;
$this->Model->recursive = 1There are 4 settings, which can be read about in detail in the CakePHP Book, but basically you can use this to make Read, Find or FindAll not perform JOINS (or perform more of them!).
Be sure that your selections only ever return the data they need to and no more.
CSS Vendor Prefixes – A potential use case
You know those moments when you know something won’t work but you try it anyway just in case the web gods look favourably on you for once? Well I just had one of those and I would like to share it, because I think this is something that the web gods should consider.
Vendor prefixes in CSS serve the purpose of allowing browsers to play about with their own implementations of new CSS rules or adding stuff totally unique to them.
There have been arguments back and forward about how useful these are in production systems and there have been some great tools made to try and reduce how much time we spend in vendor prefix hell, personally I think anything that drives the web forward is a good thing and I think prefixes do that. But anyway, enough pre-able.
What I would like to propose is that since we have vendor prefixes anyway, could we use them to target specific browsers with already known rules.
I have an edge case where it would be really nice to be able to do something like;
margin-bottom: 59px; -webkit-margin-bottom: 39px;
What this would allow me to do is set the standard margin-bottom to 59px (if it not being 60px makes you twitch, join the club!) but in webkit browsers I would like the margin to be slightly smaller.
I know this could be misused and end in really sloppy, massive CSS files – but if used with care (which I promise I would do) it would be a neat way to achieve these odd little hacks that occasionally we need to do.
Canonical and Base URLs
Canonical URLs
According to Wikipedia the word canonical in a Computer Science sense means “the usual or standard state or manner of something”, in terms of web development canonical URLs are the preferred URLs as picked by the web developer. So when a website has multiple URLs for the same content specifying a canonical URL tells search engines which link they should display to the public.
To use canonical URLs you should place something like the following in the head of your document;
<link rel="canonical" href="http://www.example.com/category/my_page.html">
Unfortunately this is only a signal, not a directive – so search engines don’t need to follow this, but from what I can see it appears to be a pretty strong signal.
What is cool is that the canonical link can point to another domain alltogther – this could be useful if you don’t have access to do other forms of redirection.
Base URLs
Base URLs let the web developer specify a documents base URI explicity, this ties in nicely with canonical links which can be relative if you wish and can help with duplicate content issues for linked content coming from your site.
To use base URLs you should place something like the following in the head of your document;
<base href="http://www.example.com/category/my_page.html">
At the first pass you are probably thinking that this is the exact same as the canonical URL we wanted to include, the difference with this is that then we do something like;
<img src="../img/myimg.png" alt="my test image" />
And this would relate to http://example.com/img/myimg.png – pretty cool eh?
This will basically mean that your canonical URL can be replicated throughout relative links in your site, which improves the chances that search engines will index the URL you want them to index.
I don’t care about SEO – why should I do this?
Some people just don’t care about ranking well in search engines, and that is fine, but I still think you should look into implementing these tags were appropriate on your website – here is why.
I am currently working on a legacy project that is a site that accepts multiple domain names, it then uses some database magic to display different sites depending on the domain. Simple enough. The only issue is that the original developers didn’t think about the need to provide a canonical URL, so b.com/a/b/c and x.com/a/b/c show the same content across different domains and unfortunately somewhere along the line Google has indexed ‘b’ as sitting under x.com instead of b.com – which just looks wrong (even if you don’t care about rank)
Granted this is just an edge base, but it is one of many that can be solved by the correct application of both canonical and base urls.
Further Reading:
Canonical Links
- http://support.google.com/webmasters/bin/answer.py?hl=en&answer=139394
- http://www.mattcutts.com/blog/seo-advice-url-canonicalization/
- http://en.wikipedia.org/wiki/URL_normalization
- http://www.seomoz.org/blog/canonical-url-tag-the-most-important-advancement-in-seo-practices-since-sitemaps
Base Links
What can The Girl With The Dragon Tattoo teach us about web design.
Absolutely nothing.
So please just enjoy stuff without having to link it to web design, or web development, or pretty much anything that is within my field of interest – I am sick of reading posts that include tenuous links to either the current trend or to something quirky that can act as link bait.
If the points you raise are valid and haven’t been covered 100 times before then please just make a standard post and let your content be the thing that makes it stand out, not the gimmick you have attached to it.

