I was recently creating some new MySQL tables that stored booleans, so I thought I would do things (what I presumed to be) properly and make them BIT(1) columns, rather than TINYINT(1). However, when I came to try to save values to this field using CakePHP, everything was saved as 1, even if the value in the data array was 0, false, “”, “0” or anything else ‘zero-ey’ or ‘falsey’.
It turns out that BIT fields are not supported by Cake, and so you should just use TINYINT(1) instead!
Furthermore, Cake will assume a TINYINT(1) field is intended as a boolean field, and will only allow you to assign it a value of 0 or 1, even though TINYINT(1) can store values from -128 to 127 (or 0 to 255 unsigned). If you try to save any value other than 0 or 1 to this field, it will be saved as 1 (but note that false, “” and an empty array will cause a save error).
The Simple Way (won’t work in IE7 or below))
All ‘modern’ browsers (see exactly which ones here: http://caniuse.com/json, but basically it’s everything except IE7 and below) natively support the JSON object, which allows you use JSON.stringify(object) to convert and object to a JSON string, and JSON.parse(string) to go back the other way. So if you’re not bothered about supporting old versions of IE, you can do it this way.
The marginally more complicated way (for full cross-browser compatibility)
json2.js (available here: https://github.com/douglascrockford/JSON-js) gives you the same stringify and parse functions as above, and is pretty small when minified. It seems to be the best option out there if you want to support the poor souls forced to (I really hoping no-one is choosing to) use IE7 or below.
We regularly write PHP, using the CakePHP framework, in Eclipse (Juno, with PHP Development Tools (PDT)). The view template files in CakePHP have the .ctp extension, which Eclipse does not, by default, recognise as PHP files, so you do not benefit from any of the helpful Eclipse PHP tools. However, you can add an association (i.e. tell Eclipse that .ctp files are PHP files), as follows:
- Go to Window > Preferences to open the Preferences box
- Go to General > Content Types in the menu
- In the Content types box, expand Text and select “PHP Content Type”
- Click “Add”
- Type “.ctp” in the box that appears and click OK
- Click OK to close the Preferences box
Note that you will have to close and then reopen any .ctp files that are already open in order for them to be recognised as PHP files.
I’ve just added a new project from an existing location in Eclipse Juno, and for some reason it wouldn’t let me create it as a PHP project. Instead, I had to just create it as a general project. Having done this, it is fairly easy to convert it to a PHP Project, by doing the following:
- Open the .project file for the new (non-PHP) project in a text editor
- Open a .project file for an existing PHP project (or, if you haven’t got an existing PHP project, create one in your workspace and use the .project file from that)
- Copy the <buildSpec> and <natures> sections from the PHP .project file (from 2. above) to the .project file for the project that you want to change to a PHP project (from 1. above)
- Save the new modified .project file and refresh the workspace
- The general project should now be a PHP project
The .project file for my PHP projects looks like this:
<?xml version="1.0" encoding="UTF-8"?>
Just a quick note to remind me, and let anyone else who tries to do this know, how to access the unique id (uuid) of a page or paragraph, and details about the current user in a JSP page in Magnolia CMS. We are watching to save, via AJAX, information about how students use pages and paragraphs (in particular self-test question paragraphs) within our Magnolia installation, and need these details in order to do this.
Displaying the node/page/paragraph ID
If you put this code in a page template, it will show you the unique ID for the page. If you put it in a paragraph template it will show you the unique id for that paragraph. These IDs do not change when you move a page, or a paragraph within a page.
<cms:out nodeDataName="uuid" var="uuid" />
Displaying the name of the current user
String user = (info.magnolia.context.MgnlContext.getUser().getName()).toString();
out.println("<p>" + user + "</p>");
Here’s the link to the Help Guide for Maths Entry Questions, if you’ve come here looking for that. This post explains why we’ve created that guide.
We’re starting to deliver Maths questions online using QTIWorks, and are putting together a help guide for users, as it is not always easy to know how to correctly represent mathematical expressions in a maths answer box.
The “Input Hints” provided in QTIWorks are of some help, but are perhaps not the most user friendly and could be improved by the addition of examples, and perhaps some reordering to place the simpler and more commonly used inputs nearer the top of the list.
- QTIWorks Input Hints (click to view full size)
To supplement (/replace) this hints box, I’ve started to write a (hopefully) simple guide to using the maths input box, with some examples. This is a work in progress, so will evolve, but hopefully is a reasonable starting point. Any comments are very welcome.