Created
April 14, 2016 06:07
-
-
Save mdmunir/176576e701b19d251b8d8f54e8470178 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\controllers; | |
use Yii; | |
use app\models\ContactInfo; | |
use yii\web\Controller; | |
use yii\filters\VerbFilter; | |
/** | |
* Description of ContactInfoController | |
* | |
* @author Misbahul D Munir <[email protected]> | |
* @since 1.0 | |
*/ | |
class ContactInfoController extends Controller | |
{ | |
public $layout = 'main.twig'; | |
public function behaviors() | |
{ | |
return [ | |
'verbs' => [ | |
'class' => VerbFilter::className(), | |
'actions' => [ | |
'delete' => ['post'], | |
], | |
], | |
]; | |
} | |
public function actionIndex() | |
{ | |
$contacts = ContactInfo::find()->all(); | |
return $this->render('index.twig', ['contacts' => $contacts]); | |
} | |
public function actionCreate() | |
{ | |
$model = new ContactInfo(); | |
if ($model->load(Yii::$app->getRequest()->post()) && $model->save()) { | |
return $this->redirect(['view', 'id' => $model->id]); | |
} | |
return $this->render('create.twig', ['model' => $model]); | |
} | |
public function actionView($id) | |
{ | |
$model = ContactInfo::findOne($id); | |
if (!$model) { | |
throw new \yii\web\NotFoundHttpException('The requested page does not exist.'); | |
} | |
return $this->render('view.twig', ['model' => $model]); | |
} | |
public function actionUpdate($id) | |
{ | |
$model = ContactInfo::findOne($id); | |
if (!$model) { | |
throw new \yii\web\NotFoundHttpException('The requested page does not exist.'); | |
} | |
if ($model->load(Yii::$app->getRequest()->post()) && $model->save()) { | |
return $this->redirect(['view', 'id' => $model->id]); | |
} | |
return $this->render('update.twig', ['model' => $model]); | |
} | |
public function actionDelete($id) | |
{ | |
$model = ContactInfo::findOne($id); | |
if (!$model) { | |
throw new \yii\web\NotFoundHttpException('The requested page does not exist.'); | |
} | |
$model->delete(); | |
return $this->redirect(['index']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment