/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new A(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['A'])) { $model->attributes = $_POST['A']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function testCaching() { $a = new A(); $a->a = 1; $a->uniqueRequiredEmail = '*****@*****.**'; $this->assertTrue($a->save()); $originalAHash = spl_object_hash($a); $id = $a->id; unset($a); $a = A::getById($id); $fromPhpAHash = spl_object_hash($a); unset($a); RedBeanModelsCache::forgetAll(true); $a = A::getById($id); $this->assertEquals(1, $a->a); $this->assertEquals('*****@*****.**', $a->uniqueRequiredEmail); $fromMemcacheAHash = spl_object_hash($a); $this->assertEquals($fromPhpAHash, $originalAHash); $this->assertNotEquals($fromMemcacheAHash, $originalAHash); }
public function testForgetAll() { $a = new A(); $a->a = 1; $a->uniqueRequiredEmail = '*****@*****.**'; $this->assertTrue($a->save()); $modelIdentifier = $a->getModelIdentifier(); $modelFromCache = RedBeanModelsCache::getModel($modelIdentifier); $this->assertEquals(1, $modelFromCache->a); $this->assertEquals('*****@*****.**', $modelFromCache->uniqueRequiredEmail); // Set some GeneralCache, which should stay in cache after cleanup GeneralCache::cacheEntry('somethingForTesting', 34); $value = GeneralCache::getEntry('somethingForTesting'); $this->assertEquals(34, $value); RedBeanModelsCache::forgetAll(); try { RedBeanModelsCache::getModel($modelIdentifier); $this->fail('NotFoundException exception is not thrown.'); } catch (NotFoundException $e) { // Data from generalCache should still be in cache $value = GeneralCache::getEntry('somethingForTesting'); $this->assertEquals(34, $value); } }
public function actionImport() { $model = new A(); if (isset($_POST['A'])) { Yii::import('ext.phpexcelreader.excel_reader2', true); $model->attributes = $_POST['A']; $import = CUploadedFile::getInstance($model, 'filee'); if ($import == null) { Yii::app()->user->setFlash('error', 'File Kosong'); $this->redirect(array('')); } else { $import->saveAs('coba/' . $import); } if ($import->type == "application/ynd.ms.excel") { $data = new Spreadsheet_Excel_Reader('/../controller/coba1.xls/'); echo $data->dump(true, true); $id = array(); $nama = array(); for ($j = 2; $j <= $data->rowcount(); $j++) { if (empty($data->sheets[0]['cells'][$j][1]) || empty($data->sheets[0]['cells'][$j][2])) { Yii::app()->user->setFlash('error', 'Data Gagal di Import (File excel harus diisi semua)'); $id[$j] = null; $nama[$j] = null; } else { $id[$j] = $data->sheets[0]['cells'][$j][1]; $nama[$j] = $data->sheets[0]['cells'][$j][2]; } } $niki = $data->rowcount(0); for ($i = 1; $i < $niki; $i++) { $model = new A(); $model->id = $id[$i]; $model->nama = $nama[$i]; $model2 = A::model()->findByPk($id[$i]); if ($model2 != null) { Yii::app()->user->setFlash('error', 'Data Gagal di Import (NIDN sudah ada sebelumnya)'); $this->redirect(array('import')); } else { $model->save(); } } $this->redirect(array('index')); } else { Yii::app()->user->setFlash('error', 'Format file tidak dikenali (format file harus .xls)'); $this->redirect(array('import')); } } $this->render('import', array('model' => $model)); /* $model = new A(); if (isset($_POST['A'])) { $model->attributes = $_POST['A']; $itu = CUploadedFile::getInstance($model, 'filee'); $path = 'coba1.xls'; //$itu->saveAs($path); $data = new Spreadsheet_Excel_Reader('coba1.xls'); }*/ }
/** * @return bool * @throws \Auth\AuthException */ public function loginSocial() { if (!$this->session->token) { if (isset($_POST['token']) && isset($_SERVER['HTTP_HOST'])) { $s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']); $result = json_decode($s, true); $userProviders = UserProviders::find(['uid' => $result['uid']])[0]; $auth = new A(); $auth->user_id = $userProviders->user_id; $auth->provider_id = $userProviders->provider_id; $auth->token = uniqid(); $auth->save(); $this->session->token = $auth->token; $this->session->user = User::find(['id' => $auth->user_id])[0]; return true; } } else { throw new AuthException('You are already logged in!'); } }