Backend qismi
Backend qismini tashkillashda Admin LTE widgetidan foydalanildi. Backend qismi to`la holda YII2 texnologiyasida tashkillangan.
MVC texnologiyasidan foydalanilgan ushbu frameworkda asosan contollerlar orqali ma’lumotlar uzatilib borildi:
namespace backend\controllers;
use Yii;
use backend\models\About;
use backend\models\AboutSearch; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\filters\VerbFilter;
use yii\filters\AccessControl;
/**
* AboutController implements the CRUD actions for About model.
*/
class AboutController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(), 'rules' => [
[
'actions' => ['login', 'error'], 'allow' => true,
], [
'actions' => ['logout', 'index', '_form', '_search', 'create', 'update', 'view','delete'], 'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(), 'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
Lists all About models.
@return mixed
*/
public function actionIndex()
{
$searchModel = new AboutSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel, 'dataProvider' => $dataProvider,
]);
}
/**
Displays a single About model.
@param integer $id
@return mixed
@throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [ 'model' => $this->findModel($id),
]);
}
/**
Creates a new About model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
*/
public function actionCreate()
{
$model = new About();
if ($model->load(Yii::$app->request->post())) {
$model->img=\yii\web\UploadedFile::getInstance($model, 'img');
$model->img->saveAs("../../frontend/web/images/".date("YMDHmi").".".$model->img->extension);
$model->img= date("YMDHmi").".".$model->img->extension;
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
Updates an existing About 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);
if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [ 'model' => $model,
]);
}
/**
Deletes an existing About 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 About model based on its primary key value.
If the model is not found, a 404 HTTP exception will be thrown.
@param integer $id
@return About the loaded model
@throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = About::findOne($id)) !== null) { return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}
Xavfsizlik tizimini tashkillashda ActiveForm dan foydalanilgan:
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\models\About */
/* @var $form yii\widgets\ActiveForm */
?>
= $form->field($model, 'title_uz')->textInput(['maxlength' => true]) ?>
= $form->field($model, 'title_en')->textInput(['maxlength' => true]) ?>
= $form->field($model, 'text_uz')->textarea(['rows' => 6]) ?>
= $form->field($model, 'text_en')->textarea(['rows' => 6]) ?>
= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>
= $form->field($model, 'tel')->textInput(['maxlength' => true]) ?>
= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
= $form->field($model, 'site')->textInput(['maxlength' => true]) ?>
= $form->field($model, 'img')->fileInput(['maxlength' => true]) ?>
= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
Xulosa
Ushbu saytni yaratish davomida aniq ma’lumotlar va topshiriq olish maqsadida Buloq boshi Nayman qishlogining 17-sonli umumta’lim maktabi direktori bilan suhabt o`tkazdim. U bergan topshiriqlar bo`yicha saytda ishlarni amalga oshrdim. Va shu bilan birga sayt tizimi to`la php Yii2 frameworkida yaratdim.
Do'stlaringiz bilan baham: |