จาก Cakebook เราได้ตัวอย่างการทำงานนี้:
public function findTagged(Query $query, array $options) {
return $this->find()
->distinct(['Articles.id'])
->matching('Tags', function ($q) use ($options) {
if (empty($options['tags'])) {
return $q->where(['Tags.title IS' => null]);
}
return $q->where(['Tags.title IN' => $options['tags']]);
});
}
ตัวอย่างเช่น ที่อยู่ article/tagged/test/new จะค้นหาบทความที่มีแท็ก "test" หรือแท็ก "new" ฉันต้องการแก้ไขโค้ดนี้ด้วยวิธี CakePHP เพื่อรับบทความที่มีแท็ก "test" และแท็ก "new"
คุณมีความคิดบ้างไหม?