CakePHP2でusersテーブルのusernameで検索処理をできる機能を作成してます。
しかし検索機能が実行されないです。
検索ボタンを押したところでなにもDBエラーも出ないので、DB側の設定と呼んでいるクエリは問題がないと思います。
また、同じような機能を記事の投稿機能にも導入しているのですが、投稿に関してはtitleの名前で検索機能がうまく動いています。そのコードと同じロジックで作成したのですが、やはり検索機能が動かない状態です
。
何か他に機能が期待通りに動かない要因が分かる方いらっしゃったら教えて頂きたいです。
Users.Controller public function find() { $userNameKeyword=null; if(!empty($this->request->data['User']['username'])) { $userNameKeyword=$this->request->data['User']['username']; } $users=$this->User->find('all',[ 'conditions' => [ 'User.username LIKE' =>'%'.$userNameKeyword.'%' ],]); $this->set('users',$users); $this->render(); } コード
find.ctp <div class="row-fluid"> <div class="span9"> <table class="table"> <tr> <th><?php echo $this->Paginator->sort('id','ID');?></th> <th><?php echo $this->Paginator->sort('username','Username');?></th> </tr> <?php foreach($users as $key => $user):?> <tr> <td><?php echo h($user['User']['id']); ?></td> <td><?php echo $this->Html->link($user['User']['username'],'/follows/profile/' . $user['User']['id']);?></td> </tr> <?php endforeach;?> </table> </div> <div class="span3"> <div class="well" style="margin-top:20px;"> <?php echo $this->Form->create('Users',array('url'=>'find')); ?> <fieldset> <legend>Search user</legend> </fieldset> <?php echo $this->Form->input('username', array('label' => 'Enter Username', 'class' => 'span12', 'empty' => true)); ?> <?php echo $this->Form->end('Search'); ?> </div> </div> </div> コード
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/30 07:41