Archive for the ‘plugin’ Category

Check your spelling mistake and save your life time.

Thursday, February 3rd, 2011

Hi, I’m back the blog :)

Sometimes I see messages about “WTF, Could not load behavior by spelling mistake as Model::actAs. waste much time…” on the Twitter. Model::actsAs is correct.
I also did such spelling mistake, and wanted to die…

I want save time and make awesome plugin “cakephp-MissingDetect-Plugin“.

This plugin detects spelling mistake of property name as follow.

  • Controller::helper ( helpers is correct)
  • Controller::component (components is correct)
  • Controller::use (uses is correct)
  • Model::actAs (actsAs is correct)

If you write wrong property name as Controller::component,  you can see alert messages on the top of screen as follow.

missingdetect-screenshot

This plugin works only on the debug mode.

It’s easy to setup, please read the Readme.
https://github.com/ichikaway/cakephp-MissingDetect-Plugin

How to extend a plugin indirectly

Wednesday, September 16th, 2009

I’m using CakePHP1.2.4
At times, I want to modify/extend a  plugin indirectly.

How do I do that?
It’s very simple, only import and inherit.

Here is the plugin(cakeplus) I made on the github.
http://github.com/ichikaway/cakeplus/tree

In this example ,   I use the behavior(add_validation_rule.php) of the cakeplus plugin and modify some method.

1. download the cakeplus plugin, and set in the “app/plugins” directory.
2. make new directory(cakeplusplus) in the “app/plugins”.

Now you can see directories as follow.


plugins/cakeplus/models/behaviors/add_validation_rule.php

plugins/cakeplusplus/models/behaviors/

3. create “ext_add_validation_rule.php”  file in “cakeplusplus/models/behaviors/” directory .


App::import('Model', 'cakeplus.AddValidationRule');
class ExtAddValidationRuleBehavior extends AddValidationRuleBehavior {

}

4. Now you can use the “ExtAddValidationRuleBehavior” class which has same functions as the “AddValidationRuleBehavior” class.

class Post extends AppModel {

var $name = 'Post';

//var $actsAs = array('Cakeplus.AddValidationRule');
var $actsAs = array('Cakeplusplus.ExtAddValidationRule');

}

5.If you want to modify or extend, you just override a method of the “AddValidationRuleBehavior” class in the “ExtAddValidationRuleBehavior” class as follow.
In this example, override the maxLengthJP method and change that function.

App::import('Model', 'cakeplus.AddValidationRule');
class ExtAddValidationRuleBehavior extends AddValidationRuleBehavior {

function maxLengthJP( &$model, $wordvalue, $length ) {
$word = array_shift($wordvalue);

//extend
$length = $length * 2;

return( mb_strlen( $word ) <= $length );
}
}

SQL syntax highlighting for Debug_kit

Wednesday, July 8th, 2009

I make SQL syntax highlighting feature for sql log panel of Debug_kit. I use GeSHi for syntax highlight.

Source code download here(include GeSHi).

You can see diff code here.

screen shot

debugkit_geshi_sql3