pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="8uqqucu" 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="gkeseye" 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="qackees" id='RbT0u'><tfoot id='RbT0u'></tfoot><dl id='RbT0u'><fieldset id='RbT0u'></fieldset></dl></div>
                          <bdo id='RbT0u'></bdo><ul id='RbT0u'></ul>
                          主站蜘蛛池模板: 高光谱相机-近红外高光谱相机厂家-高光谱成像仪-SINESPEC 赛斯拜克 | 衬塑管道_衬四氟管道厂家-淄博恒固化工设备有限公司 | 砍排机-锯骨机-冻肉切丁机-熟肉切片机-预制菜生产线一站式服务厂商 - 广州市祥九瑞盈机械设备有限公司 | 深圳美安可自动化设备有限公司,喷码机,定制喷码机,二维码喷码机,深圳喷码机,纸箱喷码机,东莞喷码机 UV喷码机,日期喷码机,鸡蛋喷码机,管芯喷码机,管内壁喷码机,喷码机厂家 | 根系分析仪,大米外观品质检测仪,考种仪,藻类鉴定计数仪,叶面积仪,菌落计数仪,抑菌圈测量仪,抗生素效价测定仪,植物表型仪,冠层分析仪-杭州万深检测仪器网 | 耐热钢-耐磨钢-山东聚金合金钢铸造有限公司 | 成都治疗尖锐湿疣比较好的医院-成都治疗尖锐湿疣那家医院好-成都西南皮肤病医院 | 珠海冷却塔降噪维修_冷却塔改造报价_凉水塔风机维修厂家- 广东康明节能空调有限公司 | 淄博不锈钢无缝管,淄博不锈钢管-鑫门物资有限公司 | 伺服电机维修、驱动器维修「安川|三菱|松下」伺服维修公司-深圳华创益 | 医疗仪器模块 健康一体机 多参数监护仪 智慧医疗仪器方案定制 血氧监护 心电监护 -朗锐慧康 | 外贮压-柜式-悬挂式-七氟丙烷-灭火器-灭火系统-药剂-价格-厂家-IG541-混合气体-贮压-非贮压-超细干粉-自动-灭火装置-气体灭火设备-探火管灭火厂家-东莞汇建消防科技有限公司 | 压滤机-洗沙泥浆处理-压泥机-山东创新华一环境工程有限公司 | 紧急切断阀_气动切断阀_不锈钢阀门_截止阀_球阀_蝶阀_闸阀-上海上兆阀门制造有限公司 | 橡胶接头_橡胶软接头_可曲挠橡胶接头-巩义市创伟机械制造有限公司 | 步进_伺服_行星减速机,微型直流电机,大功率直流电机-淄博冠意传动机械 | 清水-铝合金-建筑模板厂家-木模板价格-铝模板生产「五棵松」品牌 | 婚博会2024时间表_婚博会门票领取_婚博会地址-婚博会官网 | 儿童乐园|游乐场|淘气堡招商加盟|室内儿童游乐园配套设备|生产厂家|开心哈乐儿童乐园 | 查分易-成绩发送平台官网 | 郑州外墙清洗_郑州玻璃幕墙清洗_郑州开荒保洁-河南三恒清洗服务有限公司 | 河北中仪伟创试验仪器有限公司是专业生产沥青,土工,水泥,混凝土等试验仪器的厂家,咨询电话:13373070969 | 吸污车_吸粪车_抽粪车_电动三轮吸粪车_真空吸污车_高压清洗吸污车-远大汽车制造有限公司 | 青岛空压机,青岛空压机维修/保养,青岛空压机销售/出租公司,青岛空压机厂家电话 | 污水/卧式/潜水/钻井/矿用/大型/小型/泥浆泵,价格,参数,型号,厂家 - 安平县鼎千泵业制造厂 | 跨境物流_美国卡派_中大件运输_尾程派送_海外仓一件代发 - 广州环至美供应链平台 | 进口便携式天平,外校_十万分之一分析天平,奥豪斯工业台秤,V2000防水秤-重庆珂偌德科技有限公司(www.crdkj.com) | 扫地车厂家-山西洗地机-太原电动扫地车「大同朔州吕梁晋中忻州长治晋城洗地机」山西锦力环保科技有限公司 | 大行程影像测量仪-探针型影像测量仪-增强型影像测量仪|首丰百科 大通天成企业资质代办_承装修试电力设施许可证_增值电信业务经营许可证_无人机运营合格证_广播电视节目制作许可证 | 玉米深加工机械,玉米加工设备,玉米加工机械等玉米深加工设备制造商-河南成立粮油机械有限公司 | 首页_欧瑞传动官方网站--主营变频器、伺服系统、新能源、软起动器、PLC、HMI | 北京包装设计_标志设计公司_包装设计公司-北京思逸品牌设计 | 上海电子秤厂家,电子秤厂家价格,上海吊秤厂家,吊秤供应价格-上海佳宜电子科技有限公司 | 淬火设备-钎焊机-熔炼炉-中频炉-锻造炉-感应加热电源-退火机-热处理设备-优造节能 | 【ph计】|在线ph计|工业ph计|ph计厂家|ph计价格|酸度计生产厂家_武汉吉尔德科技有限公司 | 学习安徽网| 防渗土工膜|污水处理防渗膜|垃圾填埋场防渗膜-泰安佳路通工程材料有限公司 | 哈希余氯测定仪,分光光度计,ph在线监测仪,浊度测定仪,试剂-上海京灿精密机械有限公司 | 磁力抛光研磨机_超声波清洗机厂家_去毛刺设备-中锐达数控 | 茶楼装修设计_茶馆室内设计效果图_云臻轩茶楼装饰公司 | 污水处理设备,一体化泵站,一体化净水设备-「梦之洁环保设备厂家」 |