[
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Organizations models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new OrganizationsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider->getModels(),
]);
}
/**
* Displays a single Organizations model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
$org = $this->findModel($id);
$persons = $org->persons;
$bank = Banks::findOne($org->bank_id);
return $this->render('view', [
'model' => $org,
'persons' => $persons,
'bank' => $bank,
]);
}
/**
* Creates a new Organizations model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Organizations();
if (Yii::$app->request->isAjax) {
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->asJson(['success' => true, 'id' => $model->getPrimaryKey()]);
}
$result = [];
// The code below comes from ActiveForm::validate(). We do not need to validate the model
// again, as it was already validated by save(). Just collect the messages.
foreach ($model->getErrors() as $attribute => $errors) {
$result[yii\helpers\Html::getInputId($model, $attribute)] = $errors;
}
return $this->asJson(['validation' => $result]);
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing Organizations model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$banks = Banks::find()->asArray()->all();
//$banks2 = Banks::find()->all();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
$items = [];
foreach ($banks as $bank){
$mfo = isset($bank['mfo']) ? $bank['mfo'] . '
' : '';
$name = isset($bank['name']) ? '' . $bank['name'] .'' : '';
$address = isset($bank['address']) ? '
' . $bank['address'] : '';
$items[$bank['id']] = $mfo . $name . $address;
}
return $this->render('update', [
'model' => $model,
'banks' => $items
]);
}
/**
* Deletes an existing Organizations model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Organizations model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Organizations the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Organizations::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}