{"id":2890,"date":"2013-05-01T10:00:45","date_gmt":"2013-05-01T01:00:45","guid":{"rendered":"http:\/\/blog.bitmeister.jp\/?p=2890"},"modified":"2013-08-22T13:29:11","modified_gmt":"2013-08-22T04:29:11","slug":"cakephp2search-plugin%e3%81%ae%e6%a4%9c%e7%b4%a2%e3%83%95%e3%82%a9%e3%83%bc%e3%83%a0%e3%82%92%e6%b1%8e%e7%94%a8%e7%9a%84%e3%81%ab%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.bitmeister.jp\/?p=2890","title":{"rendered":"[CakePHP2] Search Plugin\u306e\u691c\u7d22\u30d5\u30a9\u30fc\u30e0\u3092\u6c4e\u7528\u7684\u306b\u3059\u308b"},"content":{"rendered":"<p>CakePHP\u306e\u4fbf\u5229\u306a\u691c\u7d22\u30d7\u30e9\u30b0\u30a4\u30f3\u300c<a href=\"https:\/\/github.com\/CakeDC\/search\" target=\"_blank\">Search Plugin for CakePHP<\/a>\u300d\u3067\u691c\u7d22\u30d5\u30a9\u30fc\u30e0\u3092\u6c4e\u7528\u7684\u306b\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<p>Search Plugin\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u4e0a\u8a18\u306e\u30ea\u30f3\u30af\u3067\u8aac\u660e\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u305d\u3061\u3089\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>User\u3068\u3044\u3046Model\u306bname\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u3042\u308a\u3001\u305d\u306ename\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u90e8\u5206\u4e00\u81f4\u691c\u7d22\u3059\u308b\u5834\u5408\u306e\u4f8b\u3092\u4ee5\u4e0b\u306b\u793a\u3057\u307e\u3059\u3002<br \/>\nModel\u3001Controller\u306f\u901a\u5e38\u306e\u4f7f\u3044\u65b9\u3068\u5909\u308f\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u25cfModel<\/p>\n<pre><textarea class=\"php\" name=\"code\">\t\r\n&lt;?php App::uses('AppModel', 'Model'); class User extends AppModel { \tpublic $actsAs = array('Search.Searchable'); \tpublic $filterArgs = array( \t\tarray('name' =&gt; 'search_value', 'type' =&gt; 'like', 'field' =&gt; 'User.name'),\r\n\t);\r\n}\r\n\r\n<\/textarea><\/pre>\n<p>\u25cfController<\/p>\n<pre><textarea class=\"php\" name=\"code\">\t\r\n&lt;?php App::uses('AppController', 'Controller'); class UsersController extends AppController { \tpublic $uses = array('User'); \tpublic $components = array('Search.Prg'); \tpublic $presetVars = array( \t\tarray( \t\t\t'field' =&gt; 'search_value', 'type' =&gt; 'value'\r\n\t\t),\r\n\t);\r\n\r\n\tpublic function index() {\r\n\t\t$this-&gt;Prg-&gt;commonProcess();\r\n\t\t$conditions = $this-&gt;User-&gt;parseCriteria($this-&gt;passedArgs);\r\n\r\n\t\t$this-&gt;set('users', $this-&gt;paginate(array(\r\n\t\t\t\t\t$conditions,\r\n\t\t\t\t))\r\n\t\t);\r\n\t}\r\n}\r\n<\/textarea><\/pre>\n<p>\u3053\u3053\u304b\u3089\u304c\u672c\u984c\u306eView\u306e\u90e8\u5206\u3067\u3059\u3002<br \/>\n\u307e\u305a\u3001Element\u3068\u3057\u3066\u691c\u7d22\u30d5\u30a9\u30fc\u30e0\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u25cf\u691c\u7d22\u30d5\u30a9\u30fc\u30e0\u306eElement<\/p>\n<pre><textarea class=\"php\" name=\"code\">\r\n<div class=\"search_form\">\r\n\t<?php echo $this->Form->create($model, array('url' => $url, 'class' => 'form-inline',)); ?>\r\n\t<fieldset>\r\n\t\t<?php\r\n\t\techo $this->Form->input('search_value', array(\r\n\t\t\t'type' => 'text',\r\n\t\t\t'placeholder' => isset($desc) ? $desc : false,\r\n\t\t\t'value' => isset($this->passedArgs['search_value']) ? $this->passedArgs['search_value'] : false,\r\n\t\t));\r\n\t\t?>\r\n\t\t<?php echo $this->Form->submit(__('Search')); ?>\r\n\t<\/fieldset>\r\n\t<?php echo $this->Form->end(); ?>\r\n<\/div>\r\n<\/textarea><\/pre>\n<p>\u6ce8\u76ee\u3059\u308b\u306e\u306f\uff12\u884c\u76ee\u306e <em><strong>$model<\/strong> <\/em>\u3068 <em><strong>$url<\/strong><\/em> \u3067\u3059\u3002\u3053\u308c\u3089\u306e\u5f15\u6570\u3092\u53d6\u308b\u3053\u3068\u3067\u540c\u3058\u30c7\u30b6\u30a4\u30f3\u3067\u6c4e\u7528\u7684\u306b\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u307e\u305f\u30017\u884c\u76ee\u3067\u691c\u7d22\u6587\u5b57\u5217\u5165\u529b\u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u306eplaceholder\u306e<em><strong>$desc<\/strong><\/em>\u3082\u5f15\u6570\u3068\u3057\u3066\u6307\u5b9a\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u25cfView<br \/>\n\u5148\u7a0b\u306e\u691c\u7d22\u30d5\u30a9\u30fc\u30e0\u306eElement\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n<pre><textarea class=\"php\" name=\"code\">\r\n<div class=\"users index\">\r\n\t<h2><?php echo __('Users'); ?><\/h2>\r\n\t<?php echo $this->element('search_default', array('model' => 'User', 'url' => '\/users\/index', 'desc' => '\u3053\u3053\u306b\u691c\u7d22\u6587\u5b57\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044')); ?>\r\n\t<table cellpadding=\"0\" cellspacing=\"0\">\r\n\t<tr>\r\n\t\t\t<th><?php echo $this->Paginator->sort('id'); ?><\/th>\r\n\t\t\t<th><?php echo $this->Paginator->sort('name'); ?><\/th>\r\n\t<\/tr>\r\n\t<?php foreach ($users as $user): ?>\r\n\t<tr>\r\n\t\t<td><?php echo h($user['User']['id']); ?>&nbsp;<\/td>\r\n\t\t<td><?php echo h($user['User']['name']); ?>&nbsp;<\/td>\r\n\t<\/tr>\r\n<?php endforeach; ?>\r\n\t<\/table>\r\n\t<p>\r\n\t<?php\r\n\techo $this->Paginator->counter(array(\r\n\t'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')\r\n\t));\r\n\t?>\t<\/p>\r\n\t<div class=\"paging\">\r\n\t<?php\r\n\t\techo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));\r\n\t\techo $this->Paginator->numbers(array('separator' => ''));\r\n\t\techo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));\r\n\t?>\r\n\t<\/div>\r\n<\/div>\r\n<\/textarea><\/pre>\n<p>3\u884c\u76ee\u3067\u5f15\u6570\u3092\uff08<em><strong>$model<\/strong><\/em> => User\u3001 <em><strong>$url<\/strong><\/em> => \/users\/index\u3001 <em><strong>$desc<\/strong><\/em> => \u3053\u3053\u306b\u691c\u7d22\u6587\u5b57\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\uff09\u3068\u3057\u3066\u691c\u7d22\u30d5\u30a9\u30fc\u30e0\u306eElement\u3092\u547c\u3073\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u5f8c\u306fElement\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u597d\u304d\u306a\u3088\u3046\u306b\u5909\u66f4\u3059\u308c\u3070\u3001\u72ec\u81ea\u306e\u6c4e\u7528\u691c\u7d22\u30d5\u30a9\u30fc\u30e0\u306e\u5b8c\u6210\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CakePHP\u306e\u4fbf\u5229\u306a\u691c\u7d22\u30d7\u30e9\u30b0\u30a4\u30f3\u300cSearch Plugin for CakePHP\u300d\u3067\u691c\u7d22\u30d5\u30a9\u30fc\u30e0\u3092\u6c4e\u7528\u7684\u306b\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-2890","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/2890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2890"}],"version-history":[{"count":23,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/2890\/revisions"}],"predecessor-version":[{"id":3052,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/2890\/revisions\/3052"}],"wp:attachment":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}