开发者

form multioptions select

开发者 https://www.devze.com 2023-02-19 21:06 出处:网络
This is my piece of code and i need to get more than one attribute(piece of information) back from the banner position function to view in the select or multioption box please help

This is my piece of code and i need to get more than one attribute(piece of information) back from the banner position function to view in the select or multioption box please help

class Admin_Form_Banner extends ZendX_Form_Designed {

public function init() {

$this->setEnctype(self::ENCTYPE_MULTIPART); $this->setMethod(self::METHOD_POST); $this->setMethod('post');

    // Add an email elemen开发者_如何学Ct
    $this->addElement('text', 'banner_title', array(
        'label' => 'Banner Title',
        'required' => true,
        'filters' => array('StringTrim')
    ));

    $this->addElement('text', 'banner_type', array(
        'required' => true,
        'filters' => array('StringTrim')
    ));


    $this->addElement('checkbox', 'is_active', array(
        'label' => 'Is Active',
        'required' => true,
        'filters' => array('StringTrim')
    ));

    $banner_position = new Zend_Form_Element_Select('banner_position');
    $banner_position->setMultiOptions($this->getBannerPositions())->setLabel('Banner Position');

    $this->addElement($banner_position, 'banner_position');


$this->addElement('hidden', 'file_path', array(
        'required' => true
    ));


    $this->addElement('submit', 'submit', array(
        'ignore' => true,
        'label' => ''
    ));
}

public function getBannerPositions() {
    $db = Zend_Db_Table::getDefaultAdapter();

    $bannerPosition = $db->fetchPairs($db
                            ->select()
                            ->from('banner_position'), array('id', 'banner_position'));
    return $bannerPosition;
}

}


i solve the problem by using the zend_Db_expr and the concatenation by this way i can bring the banner position and the width and the height in one multi option select box.

$bannerPosition = $db->fetchPairs($db ->select() ->from('banner_position', array( 'id' => 'id', 'display_name' => new Zend_Db_Expr("CONCAT(' ', banner_position, ' (w:', width, ' x h:', height, ')')") ) )

0

精彩评论

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