I hate CakePHP's datetime controls.
Having three (or even five with time) selectboxes for one single date is just to much. I wanted to simplify this process quite some time now. I also wanted a user friendly solution without changing my current code (with default controls). Javascript datepicker (popup) would be the most common solution. Here's my implementation.
- Append a hidden field in every <div class="input date"> element
- This hidden field is converted into jQuery datepicker control
- Two sync routines are added - they take care of populating select elements with values picked from jQuery widget and vice versa
This is how it looks like. Click on calendar icon for javascript popup (it's an image...click on it for live demo page):

Here's the code:
<script type="text/javascript">
$(document).ready(function() {
$('div.date').append('<input class="datepicker" type="hidden"/>');
$('.datepicker').datepicker({
dateFormat: 'yy-mm-dd',
buttonImage: '/uploads/calendar.png',
buttonImageOnly: true,
duration: '',
showOn: 'button',
onSelect: function(sel_date) {
var newDate = sel_date.split('-');
$(this).siblings('select').each(function(){
id = $(this).attr('id');
if (id.substring(id.length-3, id.length)=='Day') $(this).val(newDate[2]);
else if (id.substring(id.length-5, id.length)=='Month') $(this).val(newDate[1]);
else if (id.substring(id.length-4, id.length)=='Year') $(this).val(newDate[0]);
});
},
beforeShow: function() {
var year = '';
var month = '';
var day = '';
var id = '';
$(this).siblings('select').each(function() {
id = $(this).attr('id');
if (id.substring(id.length-3, id.length)=='Day') day = $(this).val();
else if (id.substring(id.length-5, id.length)=='Month') month = $(this).val();
else if (id.substring(id.length-4, id.length)=='Year') year = $(this).val();
});
$(this).val(year+'-'+month+'-'+day);
return {};
}
});
});
</script>
Edit: thanks Shubha for pointing out problem with IE. I've fixed it. Datepicker now works seamlesly in IE too.
LilFloat behavior takes care of your decimal input when your local numeric format differs from US standards.
Most of EU and other countries use comma for decimal separator and dot for thousands. Unfortunatelly CakePHP cannot handle this. Therefore I use this behavior. It automagicaly converts your decimals in a local representation into "default" version which is required for storing decimals into the database.
Wait! There is more. LilFloat behavior has also a validation method for your decimal input. Usage is as simple as adding a new validation rule. Did I mention that it can auto extract decimal places from your field type? Well, it does. Check tests for more samples.
<?php
class YourModel extends AppModel {
var $name = 'YourModel';
var $actsAs = array('LilFloat');
var $validate = array(
'decimalfield' => array(
'format' => array('rule' => 'isValidFloat'),
),
);
}
?>
You can find LilFloat behaviour in my LilCake repository. Enjoy!
I've finally implemented wysiwyg editor for LilBlogs. Currently text editor is still a default editor for posts but it will be replaced (as a default one) with one of the free html editors. For now, you can choose between TinyMCE or FckEditor.
Turning on wysiwyg editing requires two steps:
- download one of the editors mentioned above and extract it in /webroot/js folder (you have to create structure like /webroot/js/tinymce/)
- adding or changing configuration directive LilblogsPlugin.editor - like Configure::write('LilblogsPlugin.editor', 'tinymce');
I am planning to further improvements in this field - like creating editor themes, adding styles and adding file/image/media managers.
Currently I am working on bayesian filtering implementation as CakePHP behavior. I am already using bayesian filtering for comments in LilBlogs system. Currently it categorizes comments in two obvious groups: spam and ham. It just works!
This bayesian filtering is awsome. It works practicly without mistakes on one of my sites with heavier traffic and substential comment count using LilBlogs. The only downside of Bayes filtering is that it needs some learning before it becomes efficient. After this initial faze it gets only better and better.
Stay tuned! I will be releasing LilBayes behaviour shortly.
LilSearch is a CakePHP behavior which implements Zend Search Lucene component from Zend Framework. This components provides the ability to use full text searches on Models and their associations.
Main features:
- integration as behavior
- specify fields to index/search
- you can specify which associations to index and even fields of specified associations
- order results by score or by any other field
- SOON TO COME: specify fixed conditions besides full text search
LilSearch will be incorporated in LilBlogs. Before that there is a test version on this blog. Use a search field on the left to get a glance of behavior's functionality.
You can find LilSearch component in a Google Code repository. Please do try it and drop me a comment. There are tests that cover basic functionality of the LilSearch behavior.
Quick start guide:
- dowload Zend framework, copy Zend/Search folder with subfolders in /vendors - you also need Zend/Exception.php file in /vendors/Zend/Exception.php
- copy lil_cake.php into /app/models/behaviors
- add var $actsAs = array('LilSearch'); to your model
- resave your data, index will be auto build
- use $this->YourModel->lilSearch($criterio); to search your data
I promise I'll post detailed instructions and documentation in near future.