※初心者です。
symfony2・php5・phpMyadminを使用して
簡単な日記帳システムを作成しています。
(複数のユーザが存在する)
本題の検索機能追加ですが、
投稿者・タイトル・本文・投稿時期で絞り込み条件を指定し、検索できるようにしたいです。
ネットで色々調べているんですが、まだMySQLのことや
symfonyもあまり理解ができていない状態で会社にやってみろと任され、立ち往生中です。
検索機能以外の機能はもう完成している状態です。
どのファイルのどの部分に
どういう情報を入力すればスムーズにいくのでしょうか。
Controller
Veiw
Entityなど
作成の順序等を教えていただきたいです。
↓下記コードがログインユーザのページのコントローラーで
抽出用Formなど参考にしながら進めていけるかなと思考錯誤していました。
該当のソースコード
PHP
1public function indexAction(Request $request) 2 { 3 $this->canUseCheck(); 4 5 $em = $this->getDoctrine()->getManager(); 6 $fil = $this->getFilters(); 7 // 抽出用Form 8 $filterForm = $this->createForm(new LoginUserFilterType(), $this->getFilters(), array( 9 'action' => $this->generateUrl('login_user', array('_filter' => 1) 10 ))); 11 if ($this->isPost()) { 12 $filterForm->handleRequest($request); 13 if ($filterForm->isValid()) { 14 // セッションに検索条件を格納 15 $this->setFilters($filterForm->getData()); 16 } 17 } else { 18 // セッションに値が存在する場合、フォームに格納 19 $filterForm->setData($this->getFilters()); 20 } 21 22 $pagination = $this->getPagination(); 23 24 //ユーザーを取得 25 $loginUserList = $pagination->getItems(); 26 27 //IDを抜き出し 28 $loginUserIdList = array(); 29 foreach ($loginUserList as $loginUser) { 30 $loginUserIdList[] = $loginUser->getId(); 31 } 32 33 //ユーザーに紐つく権限を取得 34 $roleList = $em->getRepository('KzlBaseBundle:Role')->getRoleNameByUserIds($loginUserIdList); 35 36 return $this->render('KzlBaseBundle:LoginUser:index.html.twig', array( 37 'pagination' => $pagination, 38 'filter_form' => $filterForm->createView(), 39 'sort' => $this->getSort(), 40 'role_list' => $roleList //ユーザ毎の権限 41 // ページングが存在するか、絞込みがされている場合は検索フォームを表示する 42 //'is_search_open' => $this->isSearchBoxOpen($this->getFilters(), $pagination, $this->getMaxPerPage()), 43 //'ng_user_list' => $ngUserList, // 不正なユーザの配列 44 )); 45 }
補足情報(FW/ツールのバージョンなど)
該当のソースコード
下記が参考にするコードとして進められたのですが、権限や申込フォームのfilter_formもいまいち理解できていません。
手を付ける順序だけでもアドバイスいただけたらと思います。
よろしくお願い致します。
PHP
1{# 権限一覧 #} 2{% extends '***Bundle::layout.html.twig' %} 3 4{% block subtitle %}{{ '***.menu'|trans }}{% endblock %} 5 6{% block contents -%} 7 {% spaceless %} 8 {#フラシュメッセージ#} 9 {% include '***BaseBundle:Base:flash.html.twig' %} 10 <div class="row"> 11 <div class="col-xs-6"> 12 {# 絞込みフォーム #} 13 {{ form_start(filter_form) }}
回答1件
あなたの回答
tips
プレビュー