本文整理汇总了PHP中A::model方法的典型用法代码示例。如果您正苦于以下问题:PHP A::model方法的具体用法?PHP A::model怎么用?PHP A::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类A
的用法示例。
在下文中一共展示了A::model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionImport
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');
}*/
}
示例2: loadModel
/**
* 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 $id the ID of the model to be loaded
* @return A the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model = A::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}