/** * Finds the ItemProp model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return ItemProp the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ItemProp::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * format item prop data to json format from post * @param $itemProps * @return array * @author Lujie.Zhou(gao_lujie@live.cn, qq:821293064). */ protected function handleItemProps($itemProps) { $props = array(); $props_name = array(); foreach ($itemProps as $pid => $vid) { $itemProp = ItemProp::findOne(['prop_id' => $pid]); $pname = $itemProp->prop_name; if (is_array($vid)) { $props[$pid] = array(); $props_name[$pname] = array(); foreach ($vid as $v) { $props[$pid][] = $pid . ':' . $v; $propValue = PropValue::findOne(['value_id' => $v]); $vname = $propValue ? $propValue->value_name : $v; $props_name[$pname][] = $pname . ':' . $vname; } } else { $props[$pid] = $pid . ':' . $vid; $propValue = PropValue::findOne(['value_id' => $vid]); $vname = $propValue ? $propValue->value_name : $vid; $props_name[$pname] = $pname . ':' . $vname; } } return array(json_encode($props), json_encode($props_name)); }