久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='LVATA'></small><noframes id='LVATA'>

    <i id='LVATA'><tr id='LVATA'><dt id='LVATA'><q id='LVATA'><span id='LVATA'><b id='LVATA'><form id='LVATA'><ins id='LVATA'></ins><ul id='LVATA'></ul><sub id='LVATA'></sub></form><legend id='LVATA'></legend><bdo id='LVATA'><pre id='LVATA'><center id='LVATA'></center></pre></bdo></b><th id='LVATA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LVATA'><tfoot id='LVATA'></tfoot><dl id='LVATA'><fieldset id='LVATA'></fieldset></dl></div>

      <bdo id='LVATA'></bdo><ul id='LVATA'></ul>
    <tfoot id='LVATA'></tfoot>
      <legend id='LVATA'><style id='LVATA'><dir id='LVATA'><q id='LVATA'></q></dir></style></legend>

        symfony2 - 從數據庫中添加選擇

        symfony2 - adding choices from database(symfony2 - 從數據庫中添加選擇)
        <i id='AMete'><tr id='AMete'><dt id='AMete'><q id='AMete'><span id='AMete'><b id='AMete'><form id='AMete'><ins id='AMete'></ins><ul id='AMete'></ul><sub id='AMete'></sub></form><legend id='AMete'></legend><bdo id='AMete'><pre id='AMete'><center id='AMete'></center></pre></bdo></b><th id='AMete'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='AMete'><tfoot id='AMete'></tfoot><dl id='AMete'><fieldset id='AMete'></fieldset></dl></div>
          <tfoot id='AMete'></tfoot>

            • <bdo id='AMete'></bdo><ul id='AMete'></ul>
                <tbody id='AMete'></tbody>
                • <small id='AMete'></small><noframes id='AMete'>

                • <legend id='AMete'><style id='AMete'><dir id='AMete'><q id='AMete'></q></dir></style></legend>
                • 本文介紹了symfony2 - 從數據庫中添加選擇的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我希望用來自自定義查詢的值填充 symfony2 中的選擇框.我盡量簡化.

                  I am looking to populate a choice box in symfony2 with values from a custom query. I have tried to simplify as much as possible.

                  控制器

                  class PageController extends Controller
                  {
                  
                      public function indexAction()
                      {
                        $fields = $this->get('fields');
                        $countries =  $fields->getCountries(); // returns a array of countries e.g. array('UK', 'France', 'etc')
                        $routeSetup = new RouteSetup(); // this is the entity
                        $routeSetup->setCountries($countries); // sets the array of countries
                  
                        $chooseRouteForm = $this->createForm(new ChooseRouteForm(), $routeSetup);
                  
                  
                        return $this->render('ExampleBundle:Page:index.html.twig', array(
                          'form' => $chooseRouteForm->createView()
                        ));
                  
                      }
                  }
                  

                  選擇路由表單

                  class ChooseRouteForm extends AbstractType
                  {
                  
                    public function buildForm(FormBuilderInterface $builder, array $options)
                    {
                  
                      // errors... ideally I want this to fetch the items from the $routeSetup object 
                      $builder->add('countries', 'choice', array(
                        'choices' => $this->routeSetup->getCountries()
                      ));
                  
                    }
                  
                    public function getName()
                    {
                      return 'choose_route';
                    }
                  }
                  

                  推薦答案

                  您可以使用...將選項傳遞給您的表單

                  You could pass the choices to your form using..

                  $chooseRouteForm = $this->createForm(new ChooseRouteForm($routeSetup), $routeSetup);
                  

                  然后在您的表單中..

                  private $countries;
                  
                  public function __construct(RouteSetup $routeSetup)
                  {
                      $this->countries = $routeSetup->getCountries();
                  }
                  
                  public function buildForm(FormBuilderInterface $builder, array $options)
                  {
                      $builder->add('countries', 'choice', array(
                          'choices' => $this->countries,
                      ));
                  }
                  

                  針對 2.8+ 進行更新(和改進)

                  首先,除非將國家/地區(qū)存儲在數據庫中,否則您實際上并不需要將它們作為路線對象的一部分傳入.

                  Firstly you don't really need to pass in the countries as part of the route object unless they are going to be stored in the DB.

                  如果將可用國家/地區(qū)存儲在數據庫中,那么您可以使用事件偵聽器.如果沒有(或者如果您不想使用偵聽器),您可以在選項區(qū)域中添加國家/地區(qū).

                  If storing the available countries in the DB then you can use an event listener. If not (or if you don't want to use a listener) you can add the countries in the options area.

                  使用選項

                  在控制器中..

                  $chooseRouteForm = $this->createForm(
                      ChooseRouteForm::class,
                      // Or the full class name if using < php 5.5
                      $routeSetup,
                      array('countries' => $fields->getCountries())
                  );
                  

                  在你的表格中..

                  public function buildForm(FormBuilderInterface $builder, array $options)
                  {
                      $builder->add('countries', 'choice', array(
                          'choices' => $options['countries'],
                      ));
                  }
                  
                  public function configureOptions(OptionsResolver $resolver)
                  {
                      $resolver
                          ->setDefault('countries', null)
                          ->setRequired('countries')
                          ->setAllowedTypes('countries', array('array'))
                      ;
                  }
                  

                  使用監(jiān)聽器(如果模型中的國家/地區(qū)數組可用)

                  Using A Listener (If the countries array is available in the model)

                  在控制器中..

                  $chooseRouteForm = $this->createForm(
                      ChooseRouteForm::class,
                      // Or the full class name if using < php 5.5
                      $routeSetup
                  );
                  

                  在你的表格中..

                  public function buildForm(FormBuilderInterface $builder, array $options)
                  {
                      $builder
                          ->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) {
                              $form = $event->getForm();
                              /** @var RouteSetup $routeSetup */
                              $routeSetup = $event->getData();
                  
                              if (null === $routeSetup) {
                                  throw new Exception('RouteSetup must be injected into form');
                              }
                  
                              $form
                                  ->add('countries', 'choice', array(
                                      'choices' => $routeSetup->getCountries(),
                                  ))
                              ;
                          })
                      ;
                  }
                  

                  這篇關于symfony2 - 從數據庫中添加選擇的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                • <i id='ngvUh'><tr id='ngvUh'><dt id='ngvUh'><q id='ngvUh'><span id='ngvUh'><b id='ngvUh'><form id='ngvUh'><ins id='ngvUh'></ins><ul id='ngvUh'></ul><sub id='ngvUh'></sub></form><legend id='ngvUh'></legend><bdo id='ngvUh'><pre id='ngvUh'><center id='ngvUh'></center></pre></bdo></b><th id='ngvUh'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ngvUh'><tfoot id='ngvUh'></tfoot><dl id='ngvUh'><fieldset id='ngvUh'></fieldset></dl></div>
                    <tbody id='ngvUh'></tbody>
                • <legend id='ngvUh'><style id='ngvUh'><dir id='ngvUh'><q id='ngvUh'></q></dir></style></legend>

                        <bdo id='ngvUh'></bdo><ul id='ngvUh'></ul>
                      • <tfoot id='ngvUh'></tfoot>

                        <small id='ngvUh'></small><noframes id='ngvUh'>

                            主站蜘蛛池模板: 国产一级片 | 超碰综合 | 伊色综合久久之综合久久 | 久久久久国产精品 | 日韩精品国产精品 | 成人精品久久 | 国产精品视频一区二区三区不卡 | 欧美高清性xxxxhd | 中文字幕av在线一二三区 | 国产线视频精品免费观看视频 | 九九伊人sl水蜜桃色推荐 | 免费观看成人鲁鲁鲁鲁鲁视频 | 欧美乱码精品一区二区三区 | 国产区高清 | 国产中文字幕亚洲 | av在线播放一区二区 | 极品电影院 | 欧美激情久久久久久 | 日日摸夜夜爽人人添av | 国产探花在线精品一区二区 | 国产精品久久久久久久 | 国内精品久久久久久影视8 最新黄色在线观看 | 精品国产91乱码一区二区三区 | 中国一级特黄真人毛片免费观看 | 成人亚洲视频 | 久久一区精品 | 亚洲aⅴ一区二区 | 国产一区二区激情视频 | 亚洲精品字幕 | 91国语清晰打电话对白 | 91社影院在线观看 | 91n成人| 男人天堂99 | 狠狠婷婷综合久久久久久妖精 | 激情欧美日韩一区二区 | 亚洲精品成人av久久 | 国产亚洲精品久久情网 | 99精品欧美一区二区三区综合在线 | 日韩伦理电影免费在线观看 | 国产精品一区2区 | 中文字字幕在线中文乱码范文 |