在Magento前端获取自定义下拉列表

在Magento前端获取自定义下拉列表,magento,magento-1.7,Magento,Magento 1.7,我已经在数据库中添加了名为“数量”的自定义表。我想把它显示为前端的下拉列表 $model = Mage::getModel('quantities/quantities')->load($_product->getId()); 如何获取此数据并显示为下拉列表。我是马根托的新手。 提前感谢。您可以尝试以下方法: $model = Mage::getModel('quantities/quantities')->load($_product->getId())

我已经在数据库中添加了名为“数量”的自定义表。我想把它显示为前端的下拉列表

       $model = Mage::getModel('quantities/quantities')->load($_product->getId());
如何获取此数据并显示为下拉列表。我是马根托的新手。 提前感谢。

您可以尝试以下方法:

$model = Mage::getModel('quantities/quantities')->load($_product->getId());

<select>

<?php foreach($model->getData() as $_data): ?>

<option><?php echo $_data->getYourAttribute() ?></option>

<?php endforeach; ?>

</select>
$model=Mage::getModel('quantity/quantity')->load($\u product->getId());
假设您知道模型中包含哪些数据。如果不只是var_dump($_data)或您可以在模板(*.phtml)文件中打印\u r($_data)

,请使用如下Magento块

<?php
    $select = $this->getLayout()->createBlock('core/html_select')
    ->setName('data['.$selectName.']')
    ->setId("sel_$selectId")
    ->setClass('quantity-select')
    ->setOptions($model->getData())
    ->setValue($value);
    echo $select->getHtml();
?>

或者从头开始建造

<select name="sel_name" id="sel_id">
    <option><?php echo $this->__('Choose an Option...') ?></option>
    <?php foreach ($model->getData() as $key => $value): ?>
        <option value="<?php echo $key; ?>"><?php echo $value; ?></option>
    <?php endforeach; ?>
</select>