本文整理汇总了PHP中Region::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Region::save方法的具体用法?PHP Region::save怎么用?PHP Region::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Region
的用法示例。
在下文中一共展示了Region::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create()
{
$region = new Region();
if ($this->input->post("name")) {
$region->populate($this->input->post());
if ($region->save()) {
Notification::set(Regions::SUCCESS, "The region has been added");
redirect("/regions/");
}
}
$this->data["region"] = $region;
$this->load->view("regions/create.tpl", $this->data);
}
示例2: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Region();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Region'])) {
$model->attributes = $_POST['Region'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
//
$rules = array("regionId" => "required", "regionName" => "required");
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('/region/create')->withErrors($validator);
}
//
$region = new Region();
$region->regionID = Input::get('regionId');
$region->regionName = Input::get('regionName');
$region->save();
return Redirect::to('/region');
}
示例4: actionCreate
public function actionCreate()
{
if (Yii::app()->user->checkAccess('createRegion') == false) {
throw new CHttpException(403);
}
$data = new Region();
if (isset($_POST['Region'])) {
$data->attributes = Yii::app()->request->getPost('Region');
$data->sort_order = $data->getMaxSortOrder() + 1;
if ($data->validate() && $data->save()) {
$this->setFlashMessage(strtr('<strong>{link}</strong> 品牌地区添加成功', array('{link}' => CHtml::link($data->title, array('view', 'id' => $data->primaryKey)))));
$this->redirect($this->getReturnUrl());
}
}
$this->breadcrumbs = array('品牌地区' => array('index'), '添加');
$this->render('create', array('data' => $data, 'returnUrl' => $this->getReturnUrl()));
}
示例5: executeCity
/**
* Executes index action
*
* @param sfRequest $request A request object
*/
public function executeCity(sfWebRequest $request)
{
$wiki = file_get_contents('C:\\1\\1.htm');
preg_match_all('/<tr><td>.*?<\\/td><td>.*?<\\/td><td><a href=".*?">(.*?)<\\/a><\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>.*?<\\/td><td>(.*?)<\\/td><\\/tr>/', $wiki, $matchesarray);
$weight = array();
for ($i = 0; $i < sizeof($matchesarray[1]); $i++) {
$weight[$matchesarray[1][$i]] = floatval(str_replace(array(' ', ','), array('', '.'), $matchesarray[2][$i])) * 1000;
}
fb($weight);
$regions = array();
$cities = array();
for ($i = 1; $i <= 115; $i++) {
fb('page ' . $i);
$page = file_get_contents('http://www.voiceip.ru/home/kody_gorodov/?country_id=1&p_num=' . $i);
$page = iconv('windows-1251', 'utf-8', $page);
preg_match_all("/<tr align = center><td width = 50%>(.*?) \\((.*?)\\)<\\/td><td width = 10%>/", $page, $matchesarray2);
for ($k = 0; $k < sizeof($matchesarray2[0]); $k++) {
$city = $matchesarray2[1][$k];
$region = $matchesarray2[2][$k];
if (!isset($regions[$region])) {
$regions[$region] = array();
}
$regions[$region][] = array('name' => $city, 'weight' => isset($weight[$city]) ? $weight[$city] : 1);
$cities[] = $city;
}
}
foreach ($regions as $region => $cities) {
$r = new Region();
$r->country_id = 1;
$r->name = $region;
$r->save();
foreach ($cities as $city) {
try {
$c = new City();
$c->name = $city['name'];
$c->weight = $city['weight'];
$c->Region = $r;
$c->save();
} catch (Exception $e) {
}
}
}
}
示例6: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Region();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Region'])) {
$model->attributes = $_POST['Region'];
if (null === $model->slug || '' === $model->slug) {
$model->slug = slugify($model->name);
}
$feed = new Feed();
$feed->save();
$model->feed_id = $feed->id;
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
} else {
$feed->delete();
}
}
$this->render('create', array('model' => $model));
}
示例7: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
if ($this->CanAccess('create')) {
$model = new Region();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Region'])) {
$model->attributes = $_POST['Region'];
if ($model->CanUpdate() && $model->save()) {
// if AJAX request , we should not redirect the browser
if (!Yii::app()->request->isAjaxRequest) {
$this->redirect(array('view', 'id' => $model->id));
} else {
// UNCOMMENT THIS IF YOU WANT TO RETURN ID OF THE NEWLY CREATED
// OBJECT (USEFUL WHEN CREATING NEW OBJECTS VIA AJAX AND INFO ABOUT
// THEN NEWLY CREATED OBJECT MUST BE SENT TO THE BROWSER)
// echo CJSON::encode(array('error' => '', 'id' => $model->id));
// die();
}
} else {
throw new CHttpException(405, Yii::t('app', 'You do not have permissions to access this page.'));
}
}
if (!Yii::app()->request->isAjaxRequest) {
$this->render('create', array('model' => $model));
// IF YOU NEED DIFFERENT RENDERING FOR AJAX AND NON-AJAX CALLS,
// USE THIS LINE AND DELETE THE LINE ABOVE
// $this->render('create', array('model' => $model, 'ajaxRendering' => false));
} else {
throw new CHttpException(400, Yii::t('app', 'Bad request. The request cannot be fulfilled.'));
// IF YOU NEED DIFFERENT RENDERING FOR AJAX AND NON-AJAX CALLS,
// USE THIS LINE AND DELETE THE LINE ABOVE
// $this->renderPartial('create', array('model' => $model, 'ajaxRendering' => true));
}
} else {
throw new CHttpException(405, Yii::t('app', 'You do not have permissions to access this page.'));
}
}
示例8: actionAdd
/**
* 添加页面及操作
*/
public function actionAdd()
{
if (empty($_POST)) {
$viewData = array();
$this->render('add', $viewData);
exit;
}
$res = array('statusCode' => 200, 'message' => '添加成功!');
try {
$level = 1;
if ($_POST['parent_id']) {
$info = Region::model()->findByPk($_POST['parent_id']);
if (empty($info)) {
throw new exception('父级id不存在!');
}
$level = $info['level'] + 1;
}
$m = new Region();
$m->region_name = $_POST['region_name'];
$m->area_code = $_POST['area_code'];
$m->is_show = $_POST['is_show'];
$m->level = $level;
$m->parent_id = $_POST['parent_id'];
$flag = $m->save();
if (!$flag) {
throw new exception('添加失败');
}
} catch (Exception $e) {
$res['statusCode'] = 300;
$res['message'] = '失败【' . $e->getMessage() . '】';
}
$res['navTabId'] = 'regionList';
$res['callbackType'] = 'closeCurrent';
$res['forwardUrl'] = '/manage/region/index';
$this->ajaxDwzReturn($res);
}
示例9: addNewCity
public static function addNewCity($city)
{
$trueCity = null;
if(!empty($city)){ // добавляем город
$trueCity = new City;
$trueCity->title = $city;
$trueCity->alternative_title = $city;
$address_city = $city;
$params = array(
'geocode' => $address_city, // координаты
'format' => 'json', // формат ответа
'results' => 1, // количество выводимых результатов
'kind'=>'locality'
// 'key' => '...', // ваш api key
);
$trueRegion = $result_region = null;
$response = json_decode(@file_get_contents('http://geocode-maps.yandex.ru/1.x/?' . http_build_query($params, '', '&')));
if ($response && $response->response->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found > 0)
{
$result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos;
if($result){
$exp_str1 = explode(" ", $result);
$trueCity->latitude = $exp_str1[1];
$trueCity->longitude = $exp_str1[0];
}
$result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->name;
if($result){
$trueCity->title = $result;
$trueCity->alternative_title = $result;
}
$result_region = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->metaDataProperty->GeocoderMetaData->AddressDetails->Country->AdministrativeArea->AdministrativeAreaName;
if($result_region){
$trueRegion = Region::model()->find('LOWER(title)=:title',array(':title'=>MHelper::String()->toLower($result_region)));
if(!$trueRegion){
$trueRegion = new Region;
$trueRegion->title = $result_region;
$trueRegion->save();
}
}
}
if($trueCity->latitude)
{
// склонение
$params = array(
'format' => 'json', // формат ответа
'name'=>$trueCity->title
);
$response = CJSON::decode(@file_get_contents('http://export.yandex.ru/inflect.xml?' . http_build_query($params, '', '&')));
if ($response)
{
if(isset($response[2]))
$trueCity->rodpad = $response[2];
if(isset($response[6]))
$trueCity->mestpad = $response[6];
}
if($trueRegion){
$trueCity->region = $trueRegion->id;
}
$trueCity->pos = 0;
$trueCityCheck = City::model()->find('LOWER(title)=:title or LOWER(alternative_title)=:alternative_title',array(':title'=>MHelper::String()->toLower($trueCity->title),':alternative_title'=>MHelper::String()->toLower($trueCity->title)));
if($trueCityCheck) // потому-что ввести могут что угодно, а город обозначится только после запроса к яндексу.
return $trueCityCheck;
if($trueCity->save()){
} else {
if($trueCity->errors && isset($trueCity->errors['title'])){
if($trueCity->errors['title'][0] == 'Город с таким названием уже существует.'){
$trueCity = City::model()->find('LOWER(title)=:title or LOWER(alternative_title)=:alternative_title',array(':title'=>MHelper::String()->toLower($trueCity->title),':alternative_title'=>MHelper::String()->toLower($trueCity->title)));
}
}
}
}
}
return $trueCity;
}
示例10: import
public function import($content)
{
$header_cols = array('name' => 0, 'school_category_id' => 1, 'level_of_education' => 2, 'post' => 3, 'postal_code' => 4, 'municipality_id' => 5, 'region_id' => 6, 'country_id' => 7);
header('Content-Type: text/html; charset=utf-8');
$lines = explode("\n", $content);
for ($i = 1; $i < count($lines); ++$i) {
if (trim($lines[$i]) == '') {
continue;
}
$cols = explode(";", $lines[$i]);
// država
$country_id = 0;
$country = Country::model()->find('country=:country', array(':country' => trim($cols[$header_cols['country_id']])));
if ($country == null) {
echo Yii::t('app', 'Country does not exist! Country: ') . trim($cols[$header_cols['country_id']]);
die;
}
$country_id = $country->id;
// regija
$region = Region::model()->find('name=:name and country_id=:country_id', array(':name' => trim($cols[$header_cols['region_id']]), ':country_id' => $country_id));
if ($region == null) {
$region = new Region();
$region->country_id = $country_id;
$region->name = trim($cols[$header_cols['region_id']]);
$region->save();
}
$region_id = $region->id;
// občina
$municipality = Municipality::model()->find('name=:name and country_id=:country_id', array(':name' => trim($cols[$header_cols['municipality_id']]), ':country_id' => $country_id));
if ($municipality == null) {
$municipality = new Municipality();
$municipality->country_id = $country_id;
$municipality->name = trim($cols[$header_cols['municipality_id']]);
$municipality->save();
}
$municipality_id = $municipality->id;
$school_name = trim($cols[$header_cols['name']]);
if ($school_name[0] == '"') {
$school_name = mb_substr($school_name, 1, mb_strlen($school_name, 'UTF-8') - 2, 'UTF-8');
}
$school_name = str_replace('""', '"', $school_name);
$school = School::model()->find('name=:name and country_id=:country_id', array(':name' => $school_name, ':country_id' => $country_id));
if ($school == null) {
$school = new School();
$school->name = $school_name;
$school->country_id = $country_id;
$school->municipality_id = $municipality_id;
$school->region_id = $region_id;
$school->post = trim($cols[$header_cols['post']]);
$school->postal_code = trim($cols[$header_cols['postal_code']]);
$school->school_category_id = (int) trim($cols[$header_cols['school_category_id']]);
$school->level_of_education = (int) trim($cols[$header_cols['level_of_education']]);
$school->save();
echo 'Imported: ', $school_name, "<br />\n";
if (count($school->errors) > 0) {
print_r($school->errors);
die;
}
} else {
echo 'Already imported: ', $school_name, "<br />\n";
}
}
}
示例11: SyncZavodiWhereKategorijaActive
public static function SyncZavodiWhereKategorijaActive()
{
$schoolCategories = SchoolCategory::model()->findAll('active=:active', array(':active' => 1));
$kategorije = array();
$kategorija_map = array();
foreach ($schoolCategories as $schoolCategory) {
$kategorije[] = $schoolCategory->name;
$kategorija_map[$schoolCategory->name] = $schoolCategory->id;
}
echo "Current categories for sync:<br />";
pre_print($kategorije);
$list = self::GetRegZavod();
if (!isset($list['return'])) {
return array();
}
$list = $list['return'];
echo "Current schools to sync:<br />";
$country = Country::model()->find('country=:country', array(':country' => 'Slovenija'));
if ($country == null) {
echo "Add country Slovenija!<br />\n";
die;
}
$country_id = $country->id;
// cache all občine
$municipalities = Municipality::model()->findAll('country_id=:country_id', array(':country_id' => $country_id));
$municipality_map = array();
foreach ($municipalities as $municipality) {
$municipality_map[$municipality->name] = $municipality->id;
}
// cache all regije
$regions = Region::model()->findAll('country_id=:country_id', array(':country_id' => $country_id));
$region_map = array();
foreach ($regions as $region) {
$region_map[$region->name] = $region->id;
}
$counter = 0;
$updated = 0;
$inserted = 0;
for ($i = 0; $i < count($list); ++$i) {
if (in_array($list[$i]['KATEGORIJA'], $kategorije)) {
$counter++;
$el = $list[$i];
$school = School::model()->find('name=:name and country_id=:country_id', array(':name' => trim($el['ZAVOD_NAZIV']), ':country_id' => $country_id));
if ($school == null) {
$school = new School();
$school->name = trim($el['ZAVOD_NAZIV']);
$school->country_id = $country_id;
$inserted++;
}
$school->school_category_id = $kategorija_map[trim($el['KATEGORIJA'])];
// občina
if (!isset($municipality_map[trim($el['OBCINANAZIV'])])) {
$municipality = new Municipality();
$municipality->name = trim($el['OBCINANAZIV']);
$municipality->country_id = $country_id;
$municipality->save();
$municipality_map[trim($el['OBCINANAZIV'])] = $municipality->id;
}
$school->municipality_id = $municipality_map[trim($el['OBCINANAZIV'])];
// regija
if (!isset($region_map[trim($el['REGIJANAZIV'])])) {
$region = new Region();
$region->name = trim($el['REGIJANAZIV']);
$region->country_id = $country_id;
$region->save();
$region_map[trim($el['REGIJANAZIV'])] = $region->id;
}
$school->region_id = $region_map[trim($el['REGIJANAZIV'])];
$school->post = trim($el['POSTANAZIV']);
$school->postal_code = trim($el['POSTASIFRA']);
$school->identifier = trim($el['ZAVPRS']);
$school->headmaster = trim($el['ZAVRAVN']);
if (isset($el['ZAVDAVST'])) {
$school->tax_number = trim($el['ZAVDAVST']);
}
if ($school->save()) {
$updated++;
}
}
}
echo 'Found schools to sync: ', $counter, "<br />\n";
echo 'New schools imported: ', $inserted, "<br />\n";
echo 'Updated schools: ', $updated - $inserted, "<br />\n";
}
示例12: executeAddregion
public function executeAddregion()
{
$c = new Criteria();
$c->add(RegionPeer::NAME, $this->getRequestParameter('region'));
$exregion = RegionPeer::doSelectOne($c);
if ($exregion) {
$this->setFlash('notice', 'Region could not be added. A Region with this name already exists.');
} else {
$region = new Region();
$region->setName($this->getRequestParameter('region'));
$region->save();
$this->setFlash('notice', 'Region <b>' . $region->getName() . '</b> added successfully');
}
$this->redirect('admin/regions');
}
示例13: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$this->layout = '//layouts/blank';
$model = new Region();
// UtilHelper::dump($_REQUEST);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Region'])) {
$model->attributes = $_POST['Region'];
if (isset($_POST['Region']['manicipal']) && !isset($_POST['Region']['county'])) {
$model->pid = $_POST['Region']['manicipal'];
} elseif (isset($_POST['Region']['manicipal']) && isset($_POST['Region']['county']) && $_POST['Region']['areatype'] == Region::COUNTY) {
$model->pid = $_POST['Region']['manicipal'];
} elseif (isset($_POST['Region']['manicipal']) && isset($_POST['Region']['county']) && $_POST['Region']['areatype'] == Region::VILLAGE) {
$model->pid = $_POST['Region']['county'];
}
// UtilHelper::dump($model->attributes);
//
// Yii::app()->end();
if ($model->save()) {
echo UtilHelper::formatRightAnswer('地区创建成功');
die;
// $this->redirect(array('view','id'=>$model->id));
} else {
echo CHtml::errorSummary($model);
die;
}
// if($model->save())
// $this->redirect(array('info','id'=>$model->id));
}
$this->render('create', array('model' => $model));
}
示例14: addNewCity
public function addNewCity($city)
{
if (!empty($city)) {
// добавляем город
$trueCity = new City();
$trueCity->title = $city;
$trueCity->alternative_title = $city;
$address_city = $city;
$params = array('geocode' => $address_city, 'format' => 'json', 'results' => 1, 'kind' => 'locality');
$trueRegion = $result_region = null;
$response = json_decode(@file_get_contents('http://geocode-maps.yandex.ru/1.x/?' . http_build_query($params, '', '&')));
if ($response && $response->response->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found > 0) {
$result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos;
if ($result) {
$exp_str1 = explode(" ", $result);
$trueCity->latitude = $exp_str1[1];
$trueCity->longitude = $exp_str1[0];
}
$result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->name;
if ($result) {
$trueCity->title = $result;
$trueCity->alternative_title = $result;
}
$result_region = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->metaDataProperty->GeocoderMetaData->AddressDetails->Country->AdministrativeArea->AdministrativeAreaName;
if ($result_region) {
$trueRegion = Region::model()->find('title=:title', array(':title' => $result_region));
if (!$trueRegion) {
$trueRegion = new Region();
$trueRegion->title = $result_region;
$trueRegion->save();
}
}
}
if ($trueCity->latitude) {
// склонение
$params = array('format' => 'json', 'name' => $trueCity->title);
$response = CJSON::decode(@file_get_contents('http://export.yandex.ru/inflect.xml?' . http_build_query($params, '', '&')));
if ($response) {
if (isset($response[2])) {
$trueCity->rodpad = $response[2];
}
if (isset($response[6])) {
$trueCity->mestpad = $response[6];
}
}
if ($trueRegion) {
$trueCity->region = $trueRegion->id;
}
$trueCity->pos = 10000;
if ($trueCity->save()) {
} else {
if ($trueCity->errors && isset($trueCity->errors['title'])) {
if ($trueCity->errors['title'][0] == 'Город с таким названием уже существует.') {
$trueCity = City::model()->find('title=:title or alternative_title=:alternative_title', array(':title' => $trueCity->title, ':alternative_title' => $trueCity->title));
}
}
}
}
}
return $trueCity;
}
示例15: actionCreateRegion
public function actionCreateRegion()
{
$todo = array();
$str = "天津市:市辖区 和平区 河东区 河西区 南开区 河北区 红桥区 塘沽区 汉沽区 大港区 东丽区 西青区 津南区 北辰区 武清区 宝坻区 宁河县 静海县 蓟 县 ";
$str = str_replace(' ', '', $str);
$dd = explode(':', $str);
$todo['dd'] = $dd[0];
$todo['tt'] = explode(' ', $dd[1]);
// UtilHelper::dump($todo);
$result = array();
$file = file('./public/datas/region.txt');
$i = 0;
foreach ($file as $province) {
$province = str_replace("\r\n", '', $province);
$pos = strpos($province, ': ');
if ($pos === false) {
$region1 = $province;
} else {
$str = str_replace(' ', '', $province);
$mv = explode(': ', $str);
$county = explode(' ', $mv[1]);
$result[$region1][$mv[0]] = $county;
}
}
$return = array();
$id = 1;
$pid = 0;
foreach ($result as $key => $item) {
$return[] = array('id' => $id, 'pid' => $pid, 'region' => $key);
$pid1 = $id;
$id++;
foreach ($item as $key2 => $item2) {
$return[] = array('id' => $id, 'pid' => $pid1, 'region' => $key2);
$pid2 = $id;
$id++;
foreach ($item2 as $item3) {
if ($item3 !== '') {
$return[] = array('id' => $id, 'pid' => $pid2, 'region' => $item3);
$id++;
}
}
}
}
$fp = fopen('./public/region.txt', 'w+');
//格式化记录到新文件
foreach ($return as $todo) {
$content = '|' . $todo['id'] . '|' . $todo['region'] . "|1|" . $todo['pid'] . "|0" . "\r\n";
fwrite($fp, $content);
$region = new Region();
$region->id = $todo['id'];
$region->region = $todo['region'];
$region->pid = $todo['pid'];
$region->uid = 1;
if (!$region->save()) {
UtilHelper::writeToFile(CHtml::errorSummary($model));
}
}
fclose($fp);
UtilHelper::dump($return);
}