开发者

zend multicheckboxes form controller

开发者 https://www.devze.com 2023-03-01 15:47 出处:网络
Merged with multicheckboxes zend form multi populate. i did do the form with multicheckboxs and it works fine when insert or update but the my problem is how to populate all the multi box
Merged with multicheckboxes zend form multi populate.

i did do the form with multicheckboxs and it works fine when insert or update but the my problem is how to populate all the multi boxes that is checked form the database this is the code but it doesn't show just one checkbox is checked

      $id = (int) $this->_request->getParam('id');
    //The incoming request
    $request = $this->getRequest();
    //initialize form
    $form = new Admin_Form_DownFooterTab();
    //instance of db
    $db = Zend_Db_Table::getDefaultAdapter();

    if ($this->getRequest()->isPost()) {
        if ($form->isValid($request->getPost())) {
            if (isset($id) && $id != "") {
                $gettag = $form->getValue('tag_id');
                $gettags = count($gettag);
                try {
                    //shift the orders to
                    $select = $db->select()->from(array('t' => 'tab'), array('t.id',
                                't.title',
                    开发者_如何学编程            't.tab_position',
                                't.order',
                                't.is_active',
                                't.is_deleted'))->where('id = ?', $id);
                    $currentTab = $db->fetchRow($select);

                    $var3 = array('tab.order' => new Zend_Db_Expr('tab.order - 1'));
                    $var4 = array('tab.order >= ' . $currentTab['order'], 'is_active=1', 'is_deleted=0', 'tab_position=4');
                    $db->update('tab', $var3, $var4);



                    $var = array('tab.order' => new Zend_Db_Expr('tab.order + 1'));
                    $var2 = array('tab.order >= ' . $form->getValue('order'), 'is_active=1', 'is_deleted=0', 'tab_position=4');
                    $db->update('tab', $var, $var2);
                    $db->delete('tab_tag', array('tab_id = ?' => $id));
                    foreach ($gettag as $value) {

                        $db->insert('tab_tag',
                                array(
                                    'tag_id' => $value,
                                    'tab_id' => $id
                        ));
                    }
                    $db->update('tab', array(
                        'title' => $form->getValue('title'),
                        'body' => $form->getValue('body'),
                        'is_active' => $form->getValue('is_active'),
                        'banner_link' => $form->getValue('banner_link'),
                        'tab_path' => $form->getValue('tab_path'),
                        'link_open' => $form->getValue('link_open'),
                        'tab_position' => $form->getValue('tab_position'),
                        'tab_parent' => $form->getValue('tab_parent')
                            ),
                            array('id =?' => $id));
                    $this->flash('Tab Updated', 'admin/tab');
                } catch (Exception $e) {
                    $this->flash($e->getMessage(), 'admin/tab');
                }
            } else {
                try {
                    $formValues = $form->getValues();
                    $formValues['created_by'] = 1;
                    $formValues['created_date'] = date('Y/m/d H:i:s');
                    $formValues['is_deleted'] = 0;

                    $var = array('tab.order' => new Zend_Db_Expr('tab.order + 1'));
                    $var2 = array('tab.order >= ' . $form->getValue('order'), 'is_active=1', 'is_deleted=0', 'tab_position=4');
                    $db->update('tab', $var, $var2);


                    foreach ($gettag as $value) {

                        $db->insert('tab_tag',
                                array(
                                    'tag_id' => $value,
                                    'tab_id' => $id
                        ));
                    }
                    $db->insert('tab', array(
                        'title' => $form->getValue('title'),
                        'body' => $form->getValue('body'),
                        'is_active' => $form->getValue('is_active'),
                        'banner_link' => $form->getValue('banner_link'),
                        'tab_path' => $form->getValue('tab_path'),
                        'link_open' => $form->getValue('link_open'),
                        'tab_position' => $form->getValue('tab_position'),
                        'tab_parent' => $form->getValue('tab_parent')
                    ));
                    $this->flash('Tab inserted', 'admin/tab');
                } catch (Exception $e) {
                    $this->flash($e->getMessage(), 'admin/tab');
                }
            }
        }
    }
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */


    if (isset($id) && $id != "") {
        $values = $db->fetchRow("SELECT * FROM tab WHERE id = ?", $id);
        $form->populate($values);
    }

    $this->view->form = $form;
}

    $ddlCat_parent->setMultiOptions($cats);
    $this->view->form = $form;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消