ãã©ã°ã¤ã³ãæ¡å¼µããæ¹æ³(how to extend a plugin)
Cakephp1.2.4ãå©ç¨ãã¦ãã¾ãã
ããå¤é¨ãã©ã°ã¤ã³ã使ã£ã¦ãã¦ããã®ä¸é¨ãæ¡å¼µãããå ´åããã®ãã©ã°ã¤ã³èªä½ãæ¹è¯ãã¦ããã®ããããã§ãããããã ã¨ãã©ã°ã¤ã³ã®ã¢ãããã¼ããé£ãããªãã¾ãã
ä»åã¯ãåã®Cakeplusãã©ã°ã¤ã³ã使ã£ã¦ãããæ¡å¼µããæ¹æ³ã
çµè«ããè¨ãã¨ãCakeplusã®behaviorãã¤ã³ãã¼ããã¦ãç¶æ¿ããã ãã§ãï½
Cakeplusã¯ç¾å¨githubã§ç®¡çãã¦ãã¾ãã
http://github.com/ichikaway/cakeplus/tree
ç¾å¨ä¸è¨ã®æ©è½ãããã¾ãã
- ãã使ãããªãã¼ã·ã§ã³ãã¾ã¨ããBehavior
- ããªãã¼ã·ã§ã³ã¡ãã»ã¼ã¸ãå½éåãã¤ã¤Dryã«ããBehavior
- èªåã§hiddenã¿ã°ãçæãããã«ãã¼
- é åãã¼ã¿ãã¾ã¨ãã¦nl2brã¨h()ãé©ç¨ããã³ã³ãã¼ãã³ã
ä»åã¯ãcakeplusã®ããªãã¼ã·ã§ã³ã«ã¼ã«ãéããadd_validation_rule.phpãæ¡å¼µãã¦ã¿ã¾ããadd_validation_ruleèªä½ã®ä½¿ãæ¹ã¯ä¸è¨ãåç
§ãã ããã
http://d.hatena.ne.jp/cakephper/20090603/1244016972
ã¾ããcakeplusããã¦ã³ãã¼ããã¦è¨ç½®ãã¾ãããã©ã«ãæ§æã¨ãã¦ãplugins/cakeplusã«ãªãã¾ãã
pluginsãã©ã«ã以ä¸ã«cakeplusplusã¨ããæ¡å¼µç¨ãã©ã°ã¤ã³ãã©ã«ããä½ãã¾ãã
ä¸è¨ã®ãããªæ§æã«ãã¾ãã
plugins |- cakeplus |- cakeplusplus |- models |-behaviors
ããã¦ãcakeplusplus/models/behaviors/以ä¸ã«ext_add_validation_rule.phpã¨ãããã¡ã¤ã«ãä½æããä¸è¨å 容ãè¨è¼ãã¾ãã
<?php App::import('Model', 'cakeplus.AddValidationRule'); class ExtAddValidationRuleBehavior extends AddValidationRuleBehavior { } ?>
ãã¨ã¯ãã¢ãã«ã®behaviorå¼ã³åºãã§ãCakeplusplus.ExtAddValidationRuleãå¼ã³åºãã°ç¶æ¿ããå´ã®behaviorãå©ç¨ã§ãã¾ãã
<?php class Post extends AppModel { var $name = 'Post'; //var $actsAs = array('Cakeplus.AddValidationRule'); var $actsAs = array('Cakeplusplus.ExtAddValidationRule'); } ?>
ä¾ãã°ãadd_validation_rule.phpã®maxLengthJP()ãæ¡å¼µããããã°ãcakeplusplus/models/behaviors/ext_add_validation_rule.phpãå¤æ´ããã ãã§ããä¸è¨ã®ä¾ã¯ãæåæ°å¶éã®æ大æåæ°ããå®ç¾©ãããã®ã®2åã¾ã§è¨±ãã¨ããä¾ã§ãã
<?php 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 ); } } ?>