我有两个值的选择框,公制和英制。根据我的选择,运行控制器中的逻辑:
public function multiplyAction() {
if ($this->getRequest()->getParam('measurement') == 'imperial') {
return Mage::getSingleton('core/session')->setMeasurement('imperial');
} elseif ($this->getRequest()->getParam('measurement') == 'metric') {
return Mage::getSingleton('core/session')->setMeasurement('metric');
} else {
return false;
}
}
控制器工作正常,但它必须只返回值并跳过渲染,而是继续 URL:.../switcher/switcher/multiply/
我的表格:
<form method="post" action="<?php echo $this->getUrl('measurementswitcher/switcher/multiply'); ?>">
<select onchange="this.form.submit()" name="measurement" title="<?php echo $this->__('Preferred units') ?>" id="select-metric">
<option value="imperial" id="imperial" <?php if ( Mage::getSingleton('core/session')->getMeasurement() === "imperial" ) : ?>selected="selected"<?php endif; ?>><?php echo "Imperial (inch, gallon)" ?></option>
<option value="metric" id="metric" <?php if ( Mage::getSingleton('core/session')->getMeasurement() === "metric" ) : ?>selected="selected"<?php endif; ?>><?php echo "Metric (mm, liter)" ?></option>
</select>
</form>
也许我做错了?还是错过了一些重要的部分?谢谢你。