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

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

  1. <small id='gTl67'></small><noframes id='gTl67'>

  2. <legend id='gTl67'><style id='gTl67'><dir id='gTl67'><q id='gTl67'></q></dir></style></legend>

      • <bdo id='gTl67'></bdo><ul id='gTl67'></ul>
      <tfoot id='gTl67'></tfoot>
    1. 在 Zend Framework 2 中創建下拉列表

      Create a drop down list in Zend Framework 2(在 Zend Framework 2 中創建下拉列表)

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

            • <bdo id='FuibM'></bdo><ul id='FuibM'></ul>
            • <small id='FuibM'></small><noframes id='FuibM'>

                  <tbody id='FuibM'></tbody>
                <legend id='FuibM'><style id='FuibM'><dir id='FuibM'><q id='FuibM'></q></dir></style></legend>
                本文介紹了在 Zend Framework 2 中創建下拉列表的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                I know this sounds much more basic, still I want to post my question as it is related to Zend Framework 2. I know this form from the Zend example module

                namespace AlbumForm;
                
                use ZendFormForm;
                
                class AlbumForm extends Form
                {
                    public function __construct($name = null)
                    {
                        // we want to ignore the name passed
                        parent::__construct('album');
                        $this->setAttribute('method', 'post');
                        $this->add(array(
                            'name' => 'id',
                            'attributes' => array(
                                'type'  => 'hidden',
                            ),
                        ));
                        $this->add(array(
                            'name' => 'artist',
                            'attributes' => array(
                                'type'  => 'text',
                            ),
                            'options' => array(
                                'label' => 'Artist',
                            ),
                        ));
                        $this->add(array(
                            'name' => 'title',
                            'attributes' => array(
                                'type'  => 'text',
                            ),
                            'options' => array(
                                'label' => 'Title',
                            ),
                        ));
                        $this->add(array(
                            'name' => 'submit',
                            'attributes' => array(
                                'type'  => 'submit',
                                'value' => 'Go',
                                'id' => 'submitbutton',
                            ),
                        ));
                    }
                }
                

                And this is called in this fashion

                <?php
                $form = $this->form;
                $form->setAttribute('action', $this->url('album', array('action' => 'add')));
                $form->prepare();
                
                echo $this->form()->openTag($form);
                echo $this->formHidden($form->get('id'));
                echo $this->formRow($form->get('title'));
                echo $this->formRow($form->get('artist'));
                echo $this->formSubmit($form->get('submit'));
                echo $this->form()->closeTag();
                

                How can I add a drop down list for the artist field where the list is stored in an associative array. Since Im getting into Zend Framework 2, I wanted the suggestions from the experts. I have followed this previous post but it was somewhat unclear to me.

                解決方案

                This is one way to do it for static options.

                ....
                
                $this->add(array(
                    'type' => 'ZendFormElementSelect',
                    'name' => 'number'
                    'options' array(
                        'options' => array( '1' => 'one', '2', 'two' )
                    )
                ));
                

                Be warned....

                Because you are creating the form within a constructor you will not have access the ServiceManger. This could cause a problem if you want to populate from a database.

                Lets try something like...

                class AlbumForm extends Form implements ServiceManagerAwareInterface
                {
                
                public function __construct()
                {
                    ....
                
                    $this->add(array(
                        'type' => 'ZendFormElementSelect',
                        'name' => 'number'
                    ));
                
                    ....
                }
                

                ....

                public function initFormOptions()
                {
                    $this->get('number')->setAttribute('options', $this->getNumberOptions());
                }
                
                protected function getNumberOptions()
                {
                    // or however you want to load the data in
                    $mapper = $this->getServiceManager()->get('NumberMapper');
                    return $mapper->getList();
                }
                
                public function getServiceManager()
                {
                    if ( is_null($this->serviceManager) ) {
                        throw new Exception('The ServiceManager has not been set.');
                    }
                
                    return $this->serviceManager;
                }
                
                public function setServiceManager(ServiceManager $serviceManager)
                {
                    $this->serviceManager = $serviceManager;
                }
                

                But that's not great, rethink...

                Extending the Form so that you can create a form isn't quite right. We are not creating a new type of form, we are just setting up a form. This calls for a factory. Also, the advantages of using a factory here are that we can set it up in a way in which we can use the service manager to serve it up, that way the service manager can inject itself instead of us doing in manually from the controller. Another advantage is that we can invoke this form whenever we have the service manager.

                Another point worth making is that where it makes sense, I think it's better to take code out of the controller. The controller is not a script dump so it's nice to have objects look after themselves. What I'm trying to say is that it's good to inject an object with objects it needs, but it's not okay to just hand it the data from the controller because it creates too much of a dependency. Don't spoon feed objects from the controller, inject the spoon.

                Anyway, too much rant more code...

                class MySpankingFormService implements FactoryInterface
                {
                    public function createService(ServiceLocatorInterface $serviceManager )
                    {
                        $mySpankingNewForm = new Form;
                
                        // build that form baby,
                        // you have a service manager,
                        // inject it if you need to,
                        // otherwise just use it.
                
                        return $mySpankingNewForm;
                    }
                }
                

                controller

                <?php
                
                class FooController
                {
                    ...
                    protected function getForm()
                    {
                        if ( is_null($this->form) ) {
                            $this->form =
                                $this->getServiceManager()->get('MySpankingFormService');
                        }
                        return $this->form;
                    }
                    ...
                }
                

                module.config.php

                ...
                'service_manager' => array (
                        'factories' => array (
                            ...
                            'MySpankingFormService'
                                => 'MyNameSpacingFooMySpankingFormService',
                            ...
                

                這篇關于在 Zend Framework 2 中創建下拉列表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 找不到驅動程序)
                  <legend id='RbT0u'><style id='RbT0u'><dir id='RbT0u'><q id='RbT0u'></q></dir></style></legend>

                • <tfoot id='RbT0u'></tfoot>

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

                          <tbody id='RbT0u'></tbody>
                        <i id='RbT0u'><tr id='RbT0u'><dt id='RbT0u'><q id='RbT0u'><span id='RbT0u'><b id='RbT0u'><form id='RbT0u'><ins id='RbT0u'></ins><ul id='RbT0u'></ul><sub id='RbT0u'></sub></form><legend id='RbT0u'></legend><bdo id='RbT0u'><pre id='RbT0u'><center id='RbT0u'></center></pre></bdo></b><th id='RbT0u'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RbT0u'><tfoot id='RbT0u'></tfoot><dl id='RbT0u'><fieldset id='RbT0u'></fieldset></dl></div>
                          <bdo id='RbT0u'></bdo><ul id='RbT0u'></ul>
                          主站蜘蛛池模板: 一区中文字幕 | 国产精品国产a级 | 天天拍天天操 | 国产精品一区网站 | 99亚洲精品| 国产免费一区二区 | 成人av电影免费在线观看 | 日产久久| 亚洲综合色自拍一区 | 免费av毛片 | 久久99精品久久久 | 亚洲精品久久久久久一区二区 | 久久久这里只有17精品 | 一区二区在线不卡 | 成人国产精品久久久 | 欧美日韩成人在线 | 国产视频精品在线 | 黄色成人国产 | 日韩av第一页| va在线| 欧美色视频免费 | 午夜免费在线观看 | 国产精品一码二码三码在线 | 天天天天天天天干 | 精品久久国产 | www.亚洲区| 欧美精品一区二区在线观看 | 亚洲高清一区二区三区 | 国产在线观看一区 | 免费看片国产 | 婷婷狠狠 | 网站黄色在线免费观看 | 美女福利视频 | 欧美日韩综合视频 | 国产免费观看一级国产 | 伊人久久综合 | 久久久久亚洲 | 丁香婷婷综合激情五月色 | 日本小电影网站 | h视频在线观看免费 | 亚洲一区二区三区免费视频 |