お世話になります
こちらのサイトを参考に
http://14-00.com/archives/5
CakeDC/searchプラグインの実装をしているのですが
行き詰まってしまいどなたかヒントをいただけると嬉しいです。
エラーの内容は下記のとおりです。
error
1Notice (8): Undefined variable: data [APP/View/Tasks/find.ctp, line 8] 2Warning (2): Invalid argument supplied for foreach() [APP/View/Tasks/find.ctp, line 8]
下記が使用しているコードになります。
View /View/Tasks/find.ctp
php
1<section class="section"> 2<table class="table table-striped table-hover"> 3<?php echo $this->Html->tableHeaders(array('登録日','提供元','内容', '予算', 'カテゴリ')); ?> 4<?php foreach ($data as $task){?> 5<?php $urls=$task['Task']['url'];?> 6<?php echo $this->Html->tableCells(array( 7 $this->Time->format($task['Task']['created'],'%m-%d'), 8 $task['Company']['company_name'], 9 $this->Html->link ( $task['Task']['title'],$urls,array( 'target' => '_blank' ) ), 10 $task['Task']['price'], 11 $task['Task']['category'])); 12?> 13<?php }?> 14</table> 15<div > 16 <ul class="pagination"> 17 <?php echo $this->Paginator->prev(__('prev'), array('tag' => 'li'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a')); ?> 18 <?php echo $this->Paginator->numbers(array('separator' => '','currentTag' => 'a', 'currentClass' => 'active','tag' => 'li','first' => 1, 'ellipsis' => '<li class="disabled"><a>...</a></li>')); ?> 19 <?php echo $this->Paginator->next(__('next'), array('tag' => 'li','currentClass' => 'disabled'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a')); ?> 20 </ul> 21</div> 22</section>
Controller /TasksController.php
php
1public function find() { 2 $this->Prg->commonProcess(); 3 4 5 if (isset($this->passedArgs['search_word'])) { 6 //条件を生成 7 $conditions = $this->Task->parseCriteria($this->passedArgs); 8 9 10 $this->set('data', $this->paginate('Task')); 11 }
Model /Task.php
php
1public $actsAs = array('Search.Searchable'); 2 3// 検索対象のフィルタ設定 4public $filterArgs = array( 5 array('name' => 'search_word', 'type' => 'query', 'method' => 'multiWordSearch') 6); 7 8public function multiWordSearch($data = array()) { 9 $keyword = mb_convert_kana($data['search_word'], "s", "UTF-8"); 10 $keywords = explode(' ', $keyword); 11 12 if (count($keywords) < 2) { 13 $conditions = array( 14 //検索対象のフィールド名、適宜変更を行って下さい。 15 $this->alias.'.title LIKE' => '%' . $keyword . '%' 16 ); 17 }else{ 18 $conditions['AND'] = array(); 19 foreach ($keywords as $count => $keyword) { 20 $condition = array( 21 //検索対象のフィールド名、適宜変更を行って下さい。 22 $this->alias.'.title LIKE' => '%' . $keyword . '%' 23 ); 24 array_push($conditions['AND'], $condition); 25 } 26 } 27 return $conditions; 28} 29 public $name = 'Task';
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/03/12 07:00