TagsPluginã®å°å ¥
CakeDCæ§é
å¸ã®ãCakePHPç¨ã¿ã°ä»ããã©ã°ã¤ã³ TagsPluginãå°å
¥ãã¾ããã
http://cakedc.com/downloads/view/cakephp_tags_plugin
å°å
¥æã®ãã©ãã«ããå®éã®æåãããã¦ã¿ã°åé¤ã»ã¿ã°ã¯ã©ã¦ãã表示ããéã®çåç¹ãªã©ãããã®ã§ããããã«ã¤ãã¦è¨è¼ãã¾ãã
å°å ¥
å°å
¥æ¹æ³ã¯ä»¥ä¸ãåèã«ãã¾ãã
http://sonnygauran.co.cc/blog/2010/03/28/cakephp-tags-plugin-documentation/
ãã ããæ¸ãã¦ããéãã« cake schemaãå®è¡ããã¨ãã¨ã©ã¼ã«ãªãã¾ããã
[cake@cake databank]$ cake/console/cake schema create app -plugin tags
Welcome to CakePHP v1.3.6 Console
- -
App : app
Path: /hogehoge/databank/app
- -
Cake Schema Shell
- -
/hogehoge/databank/app/plugins/tags/config/schema/app.php could not be loaded
æ£è§£ã¯ã以ä¸ã®éãã
plugins/tags/config/schema/以ä¸ã«ããã¹ãã¼ããã¡ã¤ã«åã¯ããtags.phpããªã®ã§ãä¸è¨ãappãããtagsãã«å¤ãã¦è¡ãã¾ãã
ãã¨ãå®éã®å®è¡åã«ã -dryãã¤ãã¦åä½ç¢ºèªãã¦ã¿ã¾ãã
[cake@cake databank]$ cake/console/cake schema create tags -plugin tags -dry
Creating table(s).
Dry run for tagged :
CREATE TABLE `tagged` (
`id` varchar(36) NOT NULL,
`foreign_key` varchar(36) NOT NULL,
`tag_id` varchar(36) NOT NULL,
`model` varchar(255) NOT NULL,
`language` varchar(6) DEFAULT NULL,
`times_tagged` int(11) DEFAULT 1 NOT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL, PRIMARY KEY (`id`),
UNIQUE KEY `UNIQUE_TAGGING` (`model`, `foreign_key`, `tag_id`, `language`),
KEY `INDEX_TAGGED` (`model`),
KEY `INDEX_LANGUAGE` (`language`)) ;
Dry run for tags :
CREATE TABLE `tags` (
`id` varchar(36) NOT NULL,
`identifier` varchar(30) DEFAULT NULL,
`name` varchar(30) NOT NULL,
`keyname` varchar(30) NOT NULL,
`weight` int(2) DEFAULT 0 NOT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL, PRIMARY KEY (`id`),
UNIQUE KEY `UNIQUE_TAG` (`identifier`, `keyname`)) ;
End create.
-dryãã¯ããã¦å®è¡ããã¨ãtaggedããã³tagsãã¼ãã«ãçæããã¾ãã
ã¢ãã«ã»ãã¥ã¼ã¸ã®æ¹ä¿®ã¯ãåèURLè¨è¼éãã§OKã
ãã ããã¢ãã«ã®é¢é£ä»ããcontainè¨å®ãbindModelã§å®ç¾©ãã¦ããå ´åã¯ãããã«Tagã追å ããå¿
è¦ãããã¾ãã
$contain = array( 'User', (ä¸ç¥) + 'Tag', );
TagsPluginã«ã¯CRUDæ©è½ãä¸éãä»å±ãã¦ããã®ã§ãç»é²æ¸ã¿ã®ã¿ã°ã
http://hogehoge/admin/tags/
ã®URLã§ãåç
§ï½¥æä½ã§ãã¾ãã
(ãã ãããã«æ©è½ã¯adminå´ã®ã¿ãä¸è¬ã¦ã¼ã¶å´ã¯index,viewã®ã¿)
å¤è¨èªå対å¿ãã¡ã¤ã«ã®ä¸ã«æ¥æ¬èªè¨å®ã¯ç¡ãã®ã§ãæ¥æ¬èªè¡¨ç¤ºã¯èªä½ã®å¿
è¦ãããã¾ãã
ãã¼ã¿ã®æ§é
å®éã«ä¿åããã¦ãããã¼ã¿ã¯ã以ä¸ã®ãããªæãã§ãã
ä¾ï¼ID=62ã®Characterã«ãé«æ ¡çãã¨ããã¿ã°ãè¨å®
mysql> SELECT * FROM tagged\G *************************** 1. row *************************** id: 4d39436c-6954-4ff8-ade1-0a73c0a80b08 foreign_key: 62 tag_id: 4d39436c-16cc-4b84-86d4-0a73c0a80b08 model: Character language: jpn times_tagged: 1 created: 2011-01-21 17:27:24 modified: 2011-01-21 17:27:24 mysql> SELECT * FROM tags\G *************************** 1. row *************************** id: 4d39436c-16cc-4b84-86d4-0a73c0a80b08 identifier: name: é«æ ¡ç keyname: é«æ ¡ç weight: 0 created: 2011-01-21 17:27:24 modified: 2011-01-21 17:27:24
æå®ã®ã¢ãã«âtaggedâtagsãã¨ããå½¢ã§é¢é£ä»ãããã¦ãã¾ãã
è¤æ°ã®ãã¼ã¿ã«åãã¿ã°ãç»é²ãããã¨ãtagsã®ï¼ã¤ã®ãã¼ã¿ã«é¢é£ããtaggedãè¤æ°çæããã¾ãã
ID=62, 51ã®Characterã«ãé«æ ¡çãã¨ã¿ã°ä»ã
mysql> SELECT * FROM tagged\G *************************** 1. row *************************** id: 4d39436c-6954-4ff8-ade1-0a73c0a80b08 foreign_key: 62 tag_id: 4d39436c-16cc-4b84-86d4-0a73c0a80b08 model: Character language: jpn times_tagged: 1 created: 2011-01-21 17:27:24 modified: 2011-01-21 17:27:24 *************************** 5. row *************************** id: 4d3968f9-fec0-48d9-aaaa-0a71c0a80b08 foreign_key: 51 tag_id: 4d39436c-16cc-4b84-86d4-0a73c0a80b08 model: Character language: jpn times_tagged: 1 created: 2011-01-21 20:07:37 modified: 2011-01-21 20:07:37
ç°ãªãã¢ãã«ã§åãã¿ã°ãã¤ããå ´åããtagged.modelã®å
容ãå¤ããã ãã§ãã»ã¼åãã§ãã
ä¸æç¹ï¼ï¼ã¿ã°åé¤ã®æ¹æ³
ä¸è¨ã§è§¦ãã¾ããããdeleteã¢ã¯ã·ã§ã³ã¯ç®¡çå´ã«ããããã¾ããã
è¤æ°ã®ã¿ã°ãæå®ãã¦ããå ´åãç·¨éæã«æ¶ãã¦éä¿¡ããã°æ¶ããã®ã§ãããæå¾ã®ä¸åãæ¶ãã¾ããã空æ¬ã§éä¿¡ããã¨ãç·¨éãªãã»éä¿¡åã®å¤ãã®ã¾ã¾ã«ãªãã¾ãã
空æ¬éä¿¡æå¦çã®æ¹ä¿®ãããããã§ãã
ä¸æç¹ï¼ï¼ã¿ã°ã¯ã©ã¦ãçæé¢é£
TagsPluginã«ã¯tag_croudãã«ãã¼ãä»å±ãã¦ãããdisplay()ã«ããã¿ã°ã¯ã©ã¦ãã®åºåãå¯è½ã§ãã
ãã ãã¿ã°ã¯ã©ã¦ãã«è¯ãããã人æ°ã®ã¿ã°ã大ãã表示ãããæ©è½ã使ãã«ã¯ãä½ã追å ãããããã§ãã
ãªããã¨ããã¨ãæåãµã¤ãºã決ããã®ã¯tags.weightã®å¤ã®ãããªã®ã§ããããã®widthãæ´æ°ããå¦çç³»ããè¦å½ããã¾ããã»ã»ã»
cloneãä½ãã§ã使ç¨ç°å¢ã«åããã¦é©å®æ´æ°ãããã¨ããæå³ãªã®ãã¨æ¨æ¸¬ãã¦ãã¾ãã
ã¾ããä¼¼ããããªé
ç®ã«ãtagged.times_taggedã¨ããã«ã©ã ãããã®ã§ããã
ãã¡ãã¯ãã£ã¨ãè¬é
ç®ã§ãã»ã»ã»
ã¿ã°æ°ãã«ã¦ã³ããããªããtagged.tag_idã§GROUPãã¦ã«ã¦ã³ãããã°è¯ãã ãã®ãã¨ã
æ ¹æ¬çã«ãtimes_taggedãè¨é²ãã¦ãä½ã«ä½¿ããã®ãªã®ããç®çãä¸æã§ãã
times_taggedãæ´æ°ããã«ã¯ã
ã»Taggableããã¤ãã¢ã®taggedCounterãtrueã«ãã¦
ã»automaticTaggingãfalseã«ãã¦ãã¿ã°ä¿åsaveTags()ãé次è¡ã
ã»ãã®éã第ï¼å¼æ°ã$update=falseã«ãã
$update=false ã§ã«ã¦ã³ãããæ±ãã«ããã³ããããããã§ãã