30 Jul 2010

Basic .htaccess Modifications

This is a useful .htaccess for a basic CakePhp website. It enables
compression, normalises URLs by removing 'www' and then moves on to the
standard CakePhp redirection:
# compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css 
text/javascript
<IfModule mod_rewrite.c>
RewriteEngine on
# Convert all http://www.example.com style URLs to http://example.com
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule    ^$ app/webroot/    [L]
RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>
In certain situations - in this case our CMS - this substitution might 
be useful:
#RewriteRule    ^$ app/webroot/    [L]
RewriteRule    ^$ my-anchor-page    [L]

29 Jul 2010

INSERT rows with SELECT & mixed data

To extract values from one table, to update another where you also need
to supplement the data - in this case
(`module_type_id`,`module_id`,`zone_id`,`position`) are static
(12,42,12,1) - include the supplementary values in the SELECT statement:

INSERT page_items 
(`node_descriptor_id`,`module_type_id`,`module_id`,`zone_id`,`position`)
SELECT id ,12,42,12,1 FROM node_descriptors

20 Jul 2010

CakePHP offline manual

There used to be an offline manual - I don't remember whether it was official -  but there no longer seem to be any direct links. A little digging around revealed some answers which I thought it would be useful to share.

These are links to the manual in one page - useful for creating a PDF using Dardo Sordi Bogado's build script: http://rapidshare.com/files/218826372/manual-builder.zip. It is also very useful for searching quickly using ctrl-f in your browser.

Also see this thread: http://groups.google.com/group/cake-php/browse_thread/thread/5f45c1d0