cakePHPで4つのフィールドから絞り込み検索を制作しているのですが、コントローラでエラーででてしまいます。
以下ソースコード
View
lang
1<div class="users form"> 2<h1>検索</h1> 3<?php 4 5 6 echo 7 $this->Form->create(false,array('type'=>'post','action'=>'search')); 8 echo $this->Form->input('User.id',array( 9 'empty' => true, 10 'type' => 'text', 11 'size' => '6' 12 )); 13 14 echo $this->Form->input('User.name',array( 15 'empty' => 'true', 16 'type' => 'text')); 17 18 echo $this->Form->input('User.address',array( 19 'empty' => true, 20 'type' => 'text')); 21 22 echo $this->Form->input('User.sex', array( 23 'type' => 'select', 24 'empty' => true, 25 'options' => array( 26 'male' => '男性', 27 'female' => '女性'))); 28 29 echo $this->Form->submit("検索"); 30 echo $this->Form->end(); 31 32?>
Controller
lang
1 public function search() { 2 $data = null; 3 $keys = array('id','name','address','sex'); 4 if(!empty($this->data)){ 5 find('all',array( 'conditions' => array( 'AND' => array( 6 for($i=0; $i<=3; $i++){ 7 if($this->data['User'][$keys[$i]] != ''){ 8 array($keys[$i] => $this->data['User'][$keys[$i]]), 9 }else{ 10 array(!$keys[$i] => $this->data['User'][$keys[$i]]), 11 } 12 })))); 13 14 } 15 16 $this->set('data',$data); 17 18 }
"4つの検索をすべてANDで検索し、もしそれぞれの中身が空だった場合、すべてを表示する"
というプログラムを作りたいのですが
Error: syntax error, unexpected 'for' (T_FOR), expecting ')'
File: C:\xampp\htdocs\cake\baking\app\Controller\UsersController.php
と、でてしまい実行できません。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/04/14 05:42