本文整理匯總了PHP中app\models\Region::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Region::save方法的具體用法?PHP Region::save怎麽用?PHP Region::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Region
的用法示例。
在下文中一共展示了Region::save方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionCreate
/**
* Creates a new Region model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Region();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例2: createRegion
public function createRegion($name, $attr = [])
{
if (!($model = $this->findRegion($name))) {
$model = new Region();
$model->name = $name;
$model->setAttributes($attr);
$model->save(false);
}
return $model;
}
示例3: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$client = new HttpClient();
$provinces = json_decode('[{"children":[],"diji":"","quHuaDaiMa":"110000","quhao":"","shengji":"北京市(京)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"120000","quhao":"","shengji":"天津市(津)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"130000","quhao":"","shengji":"河北省(冀)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"140000","quhao":"","shengji":"山西省(晉)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"150000","quhao":"","shengji":"內蒙古自治區(內蒙古)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"210000","quhao":"","shengji":"遼寧省(遼)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"220000","quhao":"","shengji":"吉林省(吉)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"230000","quhao":"","shengji":"黑龍江省(黑)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"310000","quhao":"","shengji":"上海市(滬)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"320000","quhao":"","shengji":"江蘇省(蘇)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"330000","quhao":"","shengji":"浙江省(浙)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"340000","quhao":"","shengji":"安徽省(皖)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"350000","quhao":"","shengji":"福建省(閩)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"360000","quhao":"","shengji":"江西省(贛)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"370000","quhao":"","shengji":"山東省(魯)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"410000","quhao":"","shengji":"河南省(豫)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"420000","quhao":"","shengji":"湖北省(鄂)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"430000","quhao":"","shengji":"湖南省(湘)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"440000","quhao":"","shengji":"廣東省(粵)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"450000","quhao":"","shengji":"廣西壯族自治區(桂)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"460000","quhao":"","shengji":"海南省(瓊)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"500000","quhao":"","shengji":"重慶市(渝)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"510000","quhao":"","shengji":"四川省(川、蜀)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"520000","quhao":"","shengji":"貴州省(黔、貴)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"530000","quhao":"","shengji":"雲南省(滇、雲)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"540000","quhao":"","shengji":"西藏自治區(藏)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"610000","quhao":"","shengji":"陝西省(陝、秦)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"620000","quhao":"","shengji":"甘肅省(甘、隴)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"630000","quhao":"","shengji":"青海省(青)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"640000","quhao":"","shengji":"寧夏回族自治區(寧)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"650000","quhao":"","shengji":"新疆維吾爾自治區(新)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"810000","quhao":"0852","shengji":"香港特別行政區(港)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"820000","quhao":"0853","shengji":"澳門特別行政區(澳)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"710000","quhao":"","shengji":"台灣省(台)","xianji":""}]', true);
foreach ($provinces as $province) {
preg_match_all('/(.*?)\\((.*?)\\)/', $province['shengji'], $matched);
$region = new Region(array('region_name' => $matched[1][0], 'region_code' => $province['quHuaDaiMa'], 'parent_id' => 0, 'extra_attrs' => array('shortened' => $matched[2][0])));
$region->save();
echo $region->region_name . "...\r\n";
$cities = json_decode($client->post('http://202.108.98.30/selectJson', array('headers' => ['Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'], 'body' => 'shengji=' . $province['shengji']))->getBody()->read(10240000), true);
foreach ($cities as $c) {
$city = new Region(array('region_name' => $c['diji'], 'region_code' => $c['quHuaDaiMa']));
$city = $region->children()->save($city);
$dists = json_decode($client->post('http://202.108.98.30/selectJson', array('headers' => ['Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'], 'body' => 'shengji=' . $province['shengji'] . '&diji=' . $c['diji']))->getBody()->read(10240000), true);
foreach ($dists as $d) {
$dist = new Region(array('region_name' => $d['xianji'], 'region_code' => $d['quHuaDaiMa'], 'extra_attrs' => array('area_code' => $d['quhao'])));
$city->children()->save($dist);
}
}
}
echo 'done';
}