Posted on 11 April 2009, 10:43 am, by klenwell, under
Code Case.
If you’re using Pylons, the Python framework, you’re probably using FormEncode. And if you’re using FormEncode, you’ve probably have noticed, and blithely ignored, the state argument that’s the last argument to a number of the validator class methods.
So what is state and why would you want to use it?
Posted on 14 March 2009, 9:49 am, by klenwell, under
Code Case.
Problem
What if I need to compare really big numbers in PHP? Like comparing 2^66 > 3^53?
Overview
This will work:
print (int) (pow(2,66) > pow(3,53));
PHP will convert the integers to scientific notation. But this script illustrates the limitation of normal operational syntax (i.e.: pow(2,66) > pow(3,53) vs. bccomp(bcpow(2,66), bcpow(3,53),1) > 0):
$max = 1000;
foreach ( range(1,$max) as [...]
Posted on 31 January 2009, 9:28 am, by klenwell, under
Code Case.
Problem
In CakePhp, I want to invalidate a field submitted in a form and set the error message dynamically. If the error message is set by a validation parameter within the model, the new message should override that error message and be displayed by the form in the view.
Overview
Consider the following three cases as a developer:
1. [...]
Posted on 25 January 2009, 7:16 pm, by klenwell, under
Code Case.
Problem
I need to validate input from a textarea field. I want to allow a few tags, like a, i, b, etc. But everything else needs to be filtered out. And the input should be checked to see that its is nested properly.
Overview
User input sanitization and validation is one of those things that just [...]
Posted on 17 January 2009, 11:05 am, by klenwell, under
Code Case.
I wanted to use the CakePhp pagination helper to paginate some complex records. The model that the paginator was referencing had both belongsTo and hasMany associations. belongsTo associations are not a problem. hasMany, I discovered, are — which makes sense when I think about.
As the ticket notes:
You can only paginate LEFT JOIN [...]