《Query》->first();検索された中から最初のエンティティだけを取り出します。通常の検索ではエンティティの配列が偉ますが、このメソッドは1つのエンティティだけなので配列にはなりません。得られたエンティティがそのまま渡されます。
《Query》->count();検索されたエンティティの数を調べて返すものです。返値は整数値になります。
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
public function find() { $this->set('msg', null); $persons = []; if ($this->request->is('post')) { $find = $this->request->data['find']; $first = $this->Persons->find() ->where(["name like " => '%' . $find . '%']) ->first(); $count = $last = $this->Persons->find() ->where(["name like " => '%' . $find . '%']) ->count(); $last = $this->Persons->find() ->offset($count - 1) ->where(["name like " => '%' . $find . '%']) ->first(); $persons = $this->Persons->find() ->where(["name like " => '%' . $find . '%']); $msg = 'FIRST: "' . $first->name . '", LAST: "' . $last->name . '". (' . $count . ')'; $this->set('msg', $msg); } $this->set('persons', $persons); }
次へ >> |