protected function loadOModel($id) { $model = Origins::model()->findByPk($id); if (!$model) { $this->thrown; } return $model; }
public function getRateByService($from, $to, $service, $weight = 1) { $from = Origins::getOriginId($from); $to = Area::getPostCode($to); $service = self::getServiceId($service); $model = RateDomestic::model(); $criteria = new CDbCriteria(); $criteria->condition = "origin_id=" . $from; $criteria->addCondition('postal_to=' . $to); $criteria->addCondition('service_id=' . $service); $RatePrice = $model->find($criteria); if ($RatePrice != null) { $rate = $RatePrice->first_kg; if ($weight != 1) { $rate = $rate + $RatePrice->next_kg * ceil($weight - 1); } return number_format($rate, 2, '.', ''); } return false; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Origins::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
</div> <div class="row"><?php echo $form->dropDownList($model, 'companyService', CHtml::listData(RateCompanyService::model()->findAll(), 'id', 'name', 'company.name'), array('prompt' => '-- Choose Service --')); ?> <div class="row"><?php echo $form->error($model, 'companyService'); ?> </div> </div> <div class="row"><?php echo $form->label($model, 'origin'); ?> </div> <div class="row"><?php echo $form->dropDownList($model, 'origin', CHtml::listData(Origins::model()->findAll(), 'id', 'name'), array('prompt' => '-- Choose Origin --')); ?> </div> <div class="row"><?php echo $form->error($model, 'origin'); ?> </div> <div class="row"> <?php echo $form->label($model, 'to'); ?> <?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array('model' => $model, 'name' => 'to', 'sourceUrl' => array('ratePrice/ratePriceAutoComplete'), 'options' => array('select' => 'js:function(event,ui){ $("#FRatePrice_to").val(ui.item.did); $("#FRatePrice_zone_id").val(ui.item.zid);