Making of Feeding the Dragon
In this tutorial, it will show you how to create a dragon image emerging from the table. This is quite a good idea about images combination. Finally, the author also make the scene showing on an old texture paper. Very nice!
Multiple Validation as Behavior in CakePHP 1.2
After some inspiration from a recently published Bakery article, I decided to convert my multiple validation function into a Behavior. Even better, I’ve thrown it into my plugin collection to make it super easy to drop into any project.
Using the new behavior is much like using the script as it was before. You can name the validation properties to include the action name and it’ll automatically set that validation set as the default.
You can also define a specific validation set to be used with $this->ModelName->useValidationRules('ExampleSet') which will look for a validation property called validationExampleSet. If the property doesn’t exist, you’ll get an error, so be careful to match the name.
Things are a little different in that the custom validation rules aren’t automatically reset after a validation is performed. This is more a limitation of CakePHP since behaviors have beforeValidate callbacks (which is used to alter the validation set) but don’t have afterValidate callbacks (which would be used to alter them back). Instead, you have to run $this->ModelName->resetValidationRules() to set the validate property back to the default.
To set a model to make use of the behavior, just add it to the actsAs property.
class ExampleModel extends AppModel {
var $actsAs = array('Snook.MultipleValidatable');
}
That’s all you need to do! The following chunk of code is the behavior itself. It should be saved to the /app/plugins/snook/models/behaviors/ folder. You could save it in a plugin of a different name (you’d need to change the Snook prefix to the proper plugin name) or save it as a standard behavior (in which case, you’d need to remove the Snook prefix altogether).
<?php
class MultipleValidatableBehavior extends ModelBehavior {
var $__default = array();
var $__useRules = array();
function setup(&$model, $settings = array()) {
$this->__default[$model->alias] = $model->validate;
}
function beforeValidate(&$model) {
$actionSet = ‘validate’ . Inflector::camelize(Router::getParam(’action’));
if (isset($this->__useRules[$model->alias])) {
$param = ‘validate’ . $this->__useRules[$model->alias];
$model->validate = $model->{$param};
} elseif (isset($model->{$actionSet})) {
$param = $actionSet;
$model->validate = $model->{$param};
}
}
function useValidationRules(&$model, $param) {
$this->__useRules[$model->alias] = $param;
}
function resetValidationRules(&$model) {
$model->validate = $this->__default[$model->alias];
}
}
?>
I hope you enjoy it.
Firefly’s Chat-On-A-Webpage : Try it out
Firefly’s Chat-On-A-Webpage Goes Live.: Found via GigaOm, Firefly is a cool little Javascript app that sits on tops of your blog or webpage and allows unfettered chatting and interaction ability for visitors. I have enabled it on WeblogToolsCollection for the time being for people to check it out. Enable at the bottom of the page
Office life…
I’ve been freelancing since October of 2007. It’s been super fun thus far, and I don’t have any regrets for taking the risk of going solo instead of getting a regular 9-5 office job. Up until now, I have been working from home. Now this obviously has it’s pros and cons, but overall I have [...]
New WordPress themes directory
This is slightly stale news by now, but I need to get my 2cents worth. WordPress have announced the opening their brand new theme directory to the public. The directory follows the same familiar format as the plugins directory, so if you are familiar with the latter you should feel comfortable with the new directory [...]



